This commit is contained in:
Stef Heyenrath
2021-07-25 16:06:32 +02:00
parent 2531e8e688
commit b627e169a6
9 changed files with 192 additions and 160 deletions
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis;
using ProxyInterfaceSourceGenerator.Enums;
namespace ProxyInterfaceSourceGenerator.Extensions
@@ -12,7 +11,22 @@ namespace ProxyInterfaceSourceGenerator.Extensions
{
return TypeEnum.ValueTypeOrString;
}
if (p.Type.TypeKind == TypeKind.Interface)
{
return TypeEnum.Interface;
}
return TypeEnum.Complex;
}
public static TypeEnum GetTypeEnum(this IParameterSymbol p)
{
if (p.Type.IsValueType || p.Type.ToString() == "string")
{
return TypeEnum.ValueTypeOrString;
}
if (p.Type.TypeKind == TypeKind.Interface)
{
return TypeEnum.Interface;
@@ -46,36 +60,5 @@ namespace ProxyInterfaceSourceGenerator.Extensions
return $"{overrideType} {property.Name} {{ {get}{set}}}";
}
//public static string ToPropertyTextForClass(this IPropertySymbol property, string overrideType, string className)
//{
// var classNameProxy = $"{className}Proxy";
// var get = property.GetMethod != null ? $"get => new {classNameProxy}(_Instance.{property.Name}); " : string.Empty;
// var set = property.SetMethod != null ? $"set => _Instance.{property.Name} = (({classNameProxy}) value)._Instance; " : string.Empty;
// return $"{overrideType} {property.Name} {{ {get}{set}}}";
//}
public static string ToMethodText(this IMethodSymbol method)
{
var parameters = new List<string>();
foreach (var ps in method.Parameters)
{
parameters.Add($"{ps.Type} {ps.Name}");
}
return $"{method.ReturnType} {method.Name}({string.Join(", ", parameters)})";
}
public static string ToMethodTextForClass(this IMethodSymbol method)
{
var parameters = new List<string>();
foreach (var ps in method.Parameters)
{
parameters.Add($"{ps.Name}");
}
return $"{method.ToMethodText()} => _Instance.{method.Name}({string.Join(", ", parameters)});";
}
}
}