65 lines
2.2 KiB
C#
65 lines
2.2 KiB
C#
using Microsoft.CodeAnalysis;
|
|
using ProxyInterfaceSourceGenerator.Enums;
|
|
|
|
namespace ProxyInterfaceSourceGenerator.Extensions
|
|
{
|
|
internal static class SymbolExtensions
|
|
{
|
|
public static TypeEnum GetTypeEnum(this IPropertySymbol p)
|
|
{
|
|
if (p.Type.IsValueType || p.Type.ToString() == "string")
|
|
{
|
|
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;
|
|
}
|
|
|
|
return TypeEnum.Complex;
|
|
}
|
|
|
|
public static string ToPropertyText(this IPropertySymbol property, string? overrideType = null)
|
|
{
|
|
var get = property.GetMethod != null ? "get; " : string.Empty;
|
|
var set = property.SetMethod != null ? "set; " : string.Empty;
|
|
|
|
var type = !string.IsNullOrEmpty(overrideType) ? overrideType : $"{property.Type}";
|
|
|
|
return $"{type} {property.Name} {{ {get}{set}}}";
|
|
}
|
|
|
|
public static string ToPropertyTextForClass(this IPropertySymbol property)
|
|
{
|
|
var get = property.GetMethod != null ? $"get => _Instance.{property.Name}; " : string.Empty;
|
|
var set = property.SetMethod != null ? $"set => _Instance.{property.Name} = value; " : string.Empty;
|
|
|
|
return $"{property.Type} {property.Name} {{ {get}{set}}}";
|
|
}
|
|
|
|
public static string ToPropertyTextForClass(this IPropertySymbol property, string overrideType)
|
|
{
|
|
var get = property.GetMethod != null ? $"get => _mapper.Map<{overrideType}>(_Instance.{property.Name}); " : string.Empty;
|
|
var set = property.SetMethod != null ? $"set => _Instance.{property.Name} = _mapper.Map<{property.Type}>(value); " : string.Empty;
|
|
|
|
return $"{overrideType} {property.Name} {{ {get}{set}}}";
|
|
}
|
|
}
|
|
}
|