Files
ProxyGenerator/src/Speckle.ProxyGenerator/Extensions/PropertySymbolExtensions.cs
T
Adam Hathcock 5f92c81965 Fork changes
2024-05-21 16:30:10 +01:00

29 lines
1.0 KiB
C#

using Microsoft.CodeAnalysis;
using ProxyInterfaceSourceGenerator.Enums;
using ProxyInterfaceSourceGenerator.FileGenerators;
namespace ProxyInterfaceSourceGenerator.Extensions;
internal static class PropertySymbolExtensions
{
public static TypeEnum GetTypeEnum(this IPropertySymbol p) => p.Type.GetTypeEnum();
public static (string PropertyType, string? PropertyName, string GetSet)? ToPropertyDetails(this IPropertySymbol property, string? overrideType = null)
{
var getIsPublic = property.GetMethod.IsPublic();
var setIsPublic = property.SetMethod.IsPublic();
if (!getIsPublic && !setIsPublic)
{
return null;
}
var get = getIsPublic ? "get; " : string.Empty;
var set = setIsPublic ? "set; " : string.Empty;
var type = !string.IsNullOrEmpty(overrideType) ? overrideType
: BaseGenerator.FixType(property.Type.ToFullyQualifiedDisplayString(), property.NullableAnnotation);
return (type!, property.GetSanitizedName(), $"{{ {get}{set}}}");
}
}