Add global namespace support to source generators
このコミットが含まれているのは:
1 親
d698c4a6a6
コミット
284b632c45
3ファイル変更
+41
-2
検索条件に一致するファイルはありません
@@ -129,6 +129,24 @@ public sealed partial class AutoConstructorGenerator : IIncrementalGenerator
|
||||
.AddMembers(typeDeclarationSyntax);
|
||||
}
|
||||
|
||||
if (hierarchyInfo.Namespace is "")
|
||||
{
|
||||
// If there is no namespace, attach the pragma directly to the declared type,
|
||||
// and skip the namespace declaration. This will produce code as follows:
|
||||
//
|
||||
// #pragma warning disable
|
||||
//
|
||||
// <TYPE_HIERARCHY>
|
||||
return
|
||||
CompilationUnit().AddMembers(
|
||||
typeDeclarationSyntax
|
||||
.WithModifiers(TokenList(Token(
|
||||
TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))),
|
||||
SyntaxKind.PartialKeyword,
|
||||
TriviaList()))))
|
||||
.NormalizeWhitespace(eol: "\n");
|
||||
}
|
||||
|
||||
// Create the compilation unit with disabled warnings, target namespace and generated type.
|
||||
// This will produce code as follows:
|
||||
//
|
||||
|
||||
@@ -43,8 +43,10 @@ internal static class ISymbolExtensions
|
||||
INamespaceSymbol ns when ns.IsGlobalNamespace => builder,
|
||||
INamespaceSymbol ns when ns.ContainingNamespace is { IsGlobalNamespace: false }
|
||||
=> BuildFrom(ns.ContainingNamespace, builder.Insert(0, $".{ns.MetadataName}")),
|
||||
ITypeSymbol ts when ts.ContainingType is ISymbol pt => BuildFrom(pt, builder.Insert(0, $"+{ts.MetadataName}")),
|
||||
ITypeSymbol ts when ts.ContainingNamespace is ISymbol pn => BuildFrom(pn, builder.Insert(0, $".{ts.MetadataName}")),
|
||||
ITypeSymbol ts when ts.ContainingType is ISymbol containingType
|
||||
=> BuildFrom(containingType, builder.Insert(0, $"+{ts.MetadataName}")),
|
||||
ITypeSymbol ts when ts.ContainingNamespace is ISymbol containingNamespace and not INamespaceSymbol { IsGlobalNamespace: true }
|
||||
=> BuildFrom(containingNamespace, builder.Insert(0, $".{ts.MetadataName}")),
|
||||
ISymbol => BuildFrom(symbol.ContainingSymbol, builder.Insert(0, symbol.MetadataName)),
|
||||
_ => builder
|
||||
};
|
||||
|
||||
@@ -102,6 +102,25 @@ public sealed partial class IShaderGenerator
|
||||
.AddMembers(typeDeclarationSyntax);
|
||||
}
|
||||
|
||||
if (hierarchyInfo.Namespace is "")
|
||||
{
|
||||
// If there is no namespace, attach the pragma directly to the declared type,
|
||||
// and skip the namespace declaration. This is the same additional path also
|
||||
// used when generating custom constructors. This will produce code as follows:
|
||||
//
|
||||
// #pragma warning disable
|
||||
//
|
||||
// <TYPE_HIERARCHY>
|
||||
return
|
||||
CompilationUnit().AddMembers(
|
||||
typeDeclarationSyntax
|
||||
.WithModifiers(TokenList(Token(
|
||||
TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))),
|
||||
SyntaxKind.PartialKeyword,
|
||||
TriviaList()))))
|
||||
.NormalizeWhitespace(eol: "\n");
|
||||
}
|
||||
|
||||
// Create the compilation unit with disabled warnings, target namespace and generated type.
|
||||
// This will produce code as follows:
|
||||
//
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする