Implement Complex
This commit is contained in:
@@ -39,6 +39,15 @@ namespace ProxyInterfaceSourceGenerator.Extensions
|
||||
return $"{property.Type} {property.Name} {{ {get}{set}}}";
|
||||
}
|
||||
|
||||
public static string ToPropertyTextForClass(this IPropertySymbol property, string interfaceName, 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 $"{interfaceName} {property.Name} {{ {get}{set}}}";
|
||||
}
|
||||
|
||||
public static string ToMethodText(this IMethodSymbol method)
|
||||
{
|
||||
var parameters = new List<string>();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using ProxyInterfaceSourceGenerator.Enums;
|
||||
@@ -92,8 +93,17 @@ namespace {symbol.ContainingNamespace}
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
|
||||
var existing = _context.CandidateInterfaces.Values.FirstOrDefault(x => x.TypeName == property.Type.ToString());
|
||||
if (existing is not null)
|
||||
{
|
||||
str.AppendLine($" {property.ToPropertyText(existing.InterfaceName)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
str.AppendLine($" {property.ToPropertyText()}");
|
||||
}
|
||||
|
||||
str.AppendLine($" {property.ToPropertyText()}");
|
||||
str.AppendLine();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using ProxyInterfaceSourceGenerator.Enums;
|
||||
@@ -81,7 +82,16 @@ namespace {symbol.ContainingNamespace}
|
||||
// ComplexProperties
|
||||
foreach (var property in MemberHelper.GetPublicProperties(symbol, p => p.GetTypeEnum() == TypeEnum.Complex))
|
||||
{
|
||||
str.AppendLine($" public {property.ToPropertyTextForClass()}");
|
||||
var existing = _context.CandidateInterfaces.Values.FirstOrDefault(x => x.TypeName == property.Type.ToString());
|
||||
if (existing is not null)
|
||||
{
|
||||
str.AppendLine($" public {property.ToPropertyTextForClass(existing.InterfaceName, existing.ClassName)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
str.AppendLine($" public {property.ToPropertyTextForClass()}");
|
||||
}
|
||||
|
||||
str.AppendLine();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,10 @@ namespace ProxyInterfaceSourceGenerator
|
||||
|
||||
public void Initialize(GeneratorInitializationContext context)
|
||||
{
|
||||
if (!System.Diagnostics.Debugger.IsAttached)
|
||||
{
|
||||
System.Diagnostics.Debugger.Launch();
|
||||
}
|
||||
//if (!System.Diagnostics.Debugger.IsAttached)
|
||||
//{
|
||||
// System.Diagnostics.Debugger.Launch();
|
||||
//}
|
||||
|
||||
context.RegisterForSyntaxNotifications(() => new ProxySyntaxReceiver());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user