Skip to content

Commit

Permalink
Move all TypeDeclarationModels
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse committed Feb 21, 2024
1 parent d48ab65 commit 7d4af46
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
29 changes: 0 additions & 29 deletions codehelp/CodeHelpers/SymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,4 @@ public static bool RequiresUnsafe(this ITypeSymbol symbol)
{
return symbol.TypeKind == TypeKind.Pointer || symbol.TypeKind == TypeKind.FunctionPointer;
}

public static TypeDeclarationModel GetTypeDeclarationModel(this INamedTypeSymbol symbol)
{
TypeModifiers modifiers = TypeModifiers.None;
if (symbol.IsReadOnly)
{
modifiers |= TypeModifiers.IsReadOnly;
}
if (symbol.IsRefLikeType)
{
modifiers |= TypeModifiers.IsRefLikeType;
}
if (symbol.IsRecord)
{
modifiers |= TypeModifiers.IsRecord;
}

var className = symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat);
string? nspace = null;

TypeDeclarationModel? parent = null;
if (symbol.ContainingType is not null) {
parent = symbol.ContainingType.GetTypeDeclarationModel();
} else {
nspace = symbol.ContainingNamespace is { IsGlobalNamespace: false } ns ? ns.ToDisplayString() : null;
}

return new(symbol.TypeKind, modifiers, className, nspace, parent);
}
}
31 changes: 31 additions & 0 deletions codehelp/CodeHelpers/TypeDeclarationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,34 @@ public IndentedStringBuilder.IndentedScope WriteClassDeclaration(IndentedStringB
return builder.EnterScope(count);
}
}

public static class TypeDeclarationExtensions {
public static TypeDeclarationModel GetTypeDeclarationModel(this INamedTypeSymbol symbol)
{
TypeModifiers modifiers = TypeModifiers.None;
if (symbol.IsReadOnly)
{
modifiers |= TypeModifiers.IsReadOnly;
}
if (symbol.IsRefLikeType)
{
modifiers |= TypeModifiers.IsRefLikeType;
}
if (symbol.IsRecord)
{
modifiers |= TypeModifiers.IsRecord;
}

var className = symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat);
string? nspace = null;

TypeDeclarationModel? parent = null;
if (symbol.ContainingType is not null) {
parent = symbol.ContainingType.GetTypeDeclarationModel();
} else {
nspace = symbol.ContainingNamespace is { IsGlobalNamespace: false } ns ? ns.ToDisplayString() : null;
}

return new(symbol.TypeKind, modifiers, className, nspace, parent);
}
}

0 comments on commit 7d4af46

Please sign in to comment.