Add support for base (proxy) class (#29)

This commit is contained in:
Stef Heyenrath
2022-02-04 11:33:26 +01:00
committed by GitHub
parent 94d322cfb3
commit d7483d6b7e
38 changed files with 400 additions and 309 deletions
+24 -86
View File
@@ -15,10 +15,12 @@ namespace ProxyInterfaceConsumer
public static void Main()
{
//IPersonT<int> pT = new PersonTProxy<int>(new PersonT<int>());
//pT.TVal = 1;
//Console.WriteLine(JsonSerializer.Serialize(pT, JsonSerializerOptions));
//Console.WriteLine(new string('-', 80));
var t = new TestProxy(new Test());
IPersonT<int> pT = new PersonTProxy<int>(new PersonT<int>());
pT.TVal = 1;
Console.WriteLine(JsonSerializer.Serialize(pT, JsonSerializerOptions));
Console.WriteLine(new string('-', 80));
//IPersonTT<int, Program> pTT = new PersonTTProxy<int, Program>(new PersonTT<int, Program>());
//pTT.TVal1 = 42;
@@ -43,7 +45,8 @@ namespace ProxyInterfaceConsumer
Console.WriteLine(JsonSerializer.Serialize(p, JsonSerializerOptions));
}
}
public struct Test
public class Test
{
public int Id { get; set; }
@@ -51,10 +54,20 @@ namespace ProxyInterfaceConsumer
public IList<Clazz> Cs { get; set; }
public int Add(string s)
public int AddString(string s)
{
return 600;
}
public Test AddTest(Test t)
{
return new Test();
}
public Clazz AddClazz(Clazz c)
{
return new Clazz();
}
}
public sealed class Clazz
@@ -62,88 +75,13 @@ namespace ProxyInterfaceConsumer
public string Name { get; set; }
}
public interface ITest
[ProxyInterfaceGenerator.Proxy(typeof(Test))]
public partial interface ITest
{
int Id { get; set; }
IClazz C { get; }
IList<IClazz> Cs { get; set; }
int Add(string s);
}
public interface IClazz
[ProxyInterfaceGenerator.Proxy(typeof(Clazz))]
public partial 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<Clazz, ClazzProxy>();
//cfg.CreateMap<ClazzProxy, Clazz>();
cfg.CreateMap<Clazz, IClazz>();
cfg.CreateMap<IClazz, Clazz>();
}).CreateMapper();
}
public int Id
{
get => _instance.Id;
set => _instance.Id = value;
}
public IClazz C => _clazz;
public IList<IClazz> Cs2
{
get
{
//return null; // TinyMapper.Map<IList<IClazz>>(_instance.Cs); //(IList<IClazz>)_instance.Cs.Select(x => new ClazzProxy(x));
return _mapper.Map<IList<IClazz>>(_instance.Cs); //(IList<IClazz>)_instance.Cs.Select(x => new ClazzProxy(x));
}
set
{
_instance.Cs = _mapper.Map<IList<Clazz>>(value);
//_instance.Cs = TinyMapper.Map<IList<Clazz>>(value);
}
}
public IList<IClazz> Cs
{
get => _mapper.Map<IList<IClazz>>(_instance.Cs);
set => _instance.Cs = _mapper.Map<IList<Clazz>>(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; }
}
}
}