AutoMapper

This commit is contained in:
Stef Heyenrath
2021-07-25 15:26:50 +02:00
parent 3c9a292a0c
commit 2531e8e688
9 changed files with 264 additions and 96 deletions
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
namespace ProxyInterfaceSourceGenerator.FileGenerators
@@ -12,6 +14,41 @@ namespace ProxyInterfaceSourceGenerator.FileGenerators
_context = context;
}
protected string GetPropertyType(IPropertySymbol property, out Dictionary<string, string> differs)
{
differs = new Dictionary<string, string>();
var existing = _context.CandidateInterfaces.Values.FirstOrDefault(x => x.TypeName == property.Type.ToString());
if (existing is not null)
{
differs.Add(property.Type.ToString(), existing.InterfaceName);
return existing.InterfaceName;
}
if (property.Type is INamedTypeSymbol namedTypedSymbol)
{
var type = property.Type.ToString();
foreach (var typeArgument in namedTypedSymbol.TypeArguments)
{
var exist = _context.CandidateInterfaces.Values.FirstOrDefault(x => x.TypeName == typeArgument.ToString());
if (exist is not null)
{
if (!differs.ContainsKey(typeArgument.ToString()))
{
differs.Add(typeArgument.ToString(), exist.InterfaceName);
}
type = type.Replace(typeArgument.ToString(), exist.InterfaceName);
}
}
return type;
}
return property.Type.ToString();
}
protected INamedTypeSymbol GetType(string name)
{
var symbol = _context.GeneratorExecutionContext.Compilation.GetTypeByMetadataName(name);