Skip to content

Commit

Permalink
Fixed enum list handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Oct 22, 2024
1 parent 408012e commit b3ab5dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public static string GetCountAccessor(ITypeSymbol t)
{
if (t is IArrayTypeSymbol arr)
{
if (arr.ElementType.Name.StartsWith("IFormLink"))
if (arr.ElementType.Name.StartsWith("IFormLink")
|| EnumFieldGenerator.IsApplicable(arr.ElementType))
{
return LengthAccess;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ public IEnumerable<string> RequiredNamespaces(
return Enumerable.Empty<string>();
}

public static bool IsApplicable(ITypeSymbol typeSymbol)
{
typeSymbol = typeSymbol.PeelNullable();
return typeSymbol.TypeKind == TypeKind.Enum
|| (typeSymbol.BaseType is { Name: "Enum" }
&& typeSymbol.BaseType.ContainingNamespace.ToString() == "System");
}

public bool Applicable(
LoquiTypeSet obj,
CompilationUnit compilation,
ITypeSymbol typeSymbol,
string? fieldName,
bool isInsideCollection)
{
typeSymbol = typeSymbol.PeelNullable();
var ret = typeSymbol.TypeKind == TypeKind.Enum
|| (typeSymbol.BaseType is { Name: "Enum" }
&& typeSymbol.BaseType.ContainingNamespace.ToString() == "System");
if (ret) return true;
if (IsApplicable(typeSymbol)) return true;

if (obj.Getter is INamedTypeSymbol namedTypeSymbol)
{
Expand Down

0 comments on commit b3ab5dd

Please sign in to comment.