add methods

This commit is contained in:
Stef Heyenrath
2021-07-23 17:14:04 +02:00
parent ea99971400
commit 592f5df637
5 changed files with 134 additions and 19 deletions
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Text;
using Microsoft.CodeAnalysis;
namespace ProxyInterfaceSourceGenerator.Extensions
@@ -13,6 +14,14 @@ namespace ProxyInterfaceSourceGenerator.Extensions
return $"{property.Type} {property.Name} {{ {get}{set}}}";
}
public static string ToProxyCode(this IPropertySymbol property)
{
string get = property.GetMethod != null ? $"get => _instance.{property.Name}; " : string.Empty;
string set = property.SetMethod != null ? $"set => _instance.{property.Name} = value; " : string.Empty;
return $"{property.Type} {property.Name} {{ {get}{set}}}";
}
public static string ToCode(this IMethodSymbol method)
{
var parameters = new List<string>();
@@ -21,7 +30,18 @@ namespace ProxyInterfaceSourceGenerator.Extensions
parameters.Add($"{ps.Type} {ps.Name}");
}
return $"{method.ReturnType} {method.Name}({string.Join(", ", parameters)});";
return $"{method.ReturnType} {method.Name}({string.Join(", ", parameters)})";
}
public static string ToProxyCode(this IMethodSymbol method)
{
var parameters = new List<string>();
foreach (var ps in method.Parameters)
{
parameters.Add($"{ps.Name}");
}
return $"{method.ToCode()} => _instance.{method.Name}({string.Join(", ", parameters)});";
}
}
}