using AutoMapper; using DifferentNamespace; using System; using System.Collections.Generic; using System.Text.Json; namespace ProxyInterfaceConsumer { public class Program { private static JsonSerializerOptions JsonSerializerOptions = new () { WriteIndented = true }; public static void Main() { IPersonT pT = new PersonTProxy(new PersonT()); pT.TVal = 1; Console.WriteLine(JsonSerializer.Serialize(pT, JsonSerializerOptions)); Console.WriteLine(new string('-', 80)); IPersonTT pTT = new PersonTTProxy(new PersonTT()); pTT.TVal1 = 42; pTT.TVal2 = new Program(); Console.WriteLine(JsonSerializer.Serialize(pTT, JsonSerializerOptions)); Console.WriteLine(new string('-', 80)); var ap = new AddressProxy(new Address { HouseNumber = 42 }); ap.HouseNumber = -1; ap.MyEvent += delegate (object x, EventArgs a) { }; IPerson p = new PersonProxy(new Person()); p.Name = "test"; p.HelloWorld("stef"); // p.Address = ap; Console.WriteLine("DefaultValue " + p.DefaultValue()); Console.WriteLine("DefaultValue " + p.DefaultValue(42)); Console.WriteLine(JsonSerializer.Serialize(p, JsonSerializerOptions)); } } public struct Test { public int Id { get; set; } public Clazz C { get; } public IList Cs { get; set; } public int Add(string s) { return 600; } } public sealed class Clazz { public string Name { get; set; } } public interface ITest { int Id { get; set; } IClazz C { get; } IList Cs { get; set; } int Add(string s); } public interface IClazz { string Name { get; set; } } public class TestProxy : ITest { private Test _instance; private IClazz _clazz; private readonly IMapper _mapper; public TestProxy(Test instance) { _instance = instance; // _clazz = new ClazzProxy(_instance.C); _mapper = new MapperConfiguration(cfg => { //cfg.CreateMap(); //cfg.CreateMap(); cfg.CreateMap(); cfg.CreateMap(); }).CreateMapper(); } public int Id { get => _instance.Id; set => _instance.Id = value; } public IClazz C => _clazz; public IList Cs2 { get { //return null; // TinyMapper.Map>(_instance.Cs); //(IList)_instance.Cs.Select(x => new ClazzProxy(x)); return _mapper.Map>(_instance.Cs); //(IList)_instance.Cs.Select(x => new ClazzProxy(x)); } set { _instance.Cs = _mapper.Map>(value); //_instance.Cs = TinyMapper.Map>(value); } } public IList Cs { get => _mapper.Map>(_instance.Cs); set => _instance.Cs = _mapper.Map>(value); } public int Add(string s) => _instance.Add(s); } public class ClazzProxy : IClazz { private Clazz _instance; public ClazzProxy(Clazz instance) { _instance = instance; } public string Name { get => _instance.Name; set => _instance.Name = value; } } }