Use Mapster as mapper (#39)

* mapster

* ,

* .

* ...

* .

* .

* .

* .

* .

* .

* int

* .

* ;
This commit is contained in:
Stef Heyenrath
2022-09-05 21:26:02 +02:00
committed by GitHub
parent 4b9b47ba9d
commit 0e57de17c3
39 changed files with 378 additions and 405 deletions
@@ -0,0 +1,27 @@
using System.Text;
using ProxyInterfaceSourceGenerator.Extensions;
namespace ProxyInterfaceSourceGenerator.FileGenerators;
internal partial class ProxyClassesGenerator
{
private string GenerateMapperConfigurationForMapster()
{
var str = new StringBuilder();
foreach (var replacedType in Context.ReplacedTypes)
{
TryFindProxyDataByTypeName(replacedType.Key, out var fullTypeName);
var classNameProxy = $"{fullTypeName!.Namespace}.{fullTypeName.ShortTypeName}Proxy";
var instance = $"instance{(replacedType.Key + replacedType.Value).GetDeterministicHashCodeAsString()}";
var proxy = $"proxy{(replacedType.Value + replacedType.Key).GetDeterministicHashCodeAsString()}";
str.AppendLine($" Mapster.TypeAdapterConfig<{replacedType.Key}, {replacedType.Value}>.NewConfig().ConstructUsing({instance} => new {classNameProxy}({instance}));");
str.AppendLine($" Mapster.TypeAdapterConfig<{replacedType.Value}, {replacedType.Key}>.NewConfig().MapWith({proxy} => (({classNameProxy}) {proxy})._Instance);");
str.AppendLine();
}
return str.ToString();
}
}