Added attributes to generated classes
このコミットが含まれているのは:
1 親
d06e8fd3ed
コミット
4e39eb0ab8
2ファイル変更
+40
-5
検索条件に一致するファイルはありません
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
@@ -29,6 +30,19 @@ namespace ComputeSharp.SourceGenerators
|
||||
from structDeclaration in tree.GetRoot().DescendantNodes().OfType<StructDeclarationSyntax>()
|
||||
select structDeclaration).ToImmutableArray();
|
||||
|
||||
// Type attributes
|
||||
AttributeListSyntax[] attributes = new[]
|
||||
{
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName("EditorBrowsable")).AddArgumentListArguments(
|
||||
AttributeArgument(ParseExpression("EditorBrowsableState.Never"))))),
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName("Obsolete")).AddArgumentListArguments(
|
||||
AttributeArgument(LiteralExpression(
|
||||
SyntaxKind.StringLiteralExpression,
|
||||
Literal("This type is not intended to be used directly by user code"))))))
|
||||
};
|
||||
|
||||
foreach (StructDeclarationSyntax structDeclaration in structDeclarations)
|
||||
{
|
||||
SemanticModel semanticModel = context.Compilation.GetSemanticModel(structDeclaration.SyntaxTree);
|
||||
@@ -68,7 +82,7 @@ namespace ComputeSharp.SourceGenerators
|
||||
ClassDeclaration("HashCodeProvider").AddModifiers(
|
||||
Token(SyntaxKind.InternalKeyword),
|
||||
Token(SyntaxKind.StaticKeyword),
|
||||
Token(SyntaxKind.PartialKeyword)).AddMembers(
|
||||
Token(SyntaxKind.PartialKeyword)).AddAttributeLists(attributes).AddMembers(
|
||||
MethodDeclaration(
|
||||
PredefinedType(Token(SyntaxKind.IntKeyword)),
|
||||
Identifier("CombineHash")).AddAttributeLists(
|
||||
@@ -88,6 +102,9 @@ namespace ComputeSharp.SourceGenerators
|
||||
.NormalizeWhitespace()
|
||||
.ToFullString();
|
||||
|
||||
// Clear the attribute list to avoid duplicates
|
||||
attributes = Array.Empty<AttributeListSyntax>();
|
||||
|
||||
// Add the method source attribute
|
||||
context.AddSource(structDeclarationSymbol.GetGeneratedFileName<IComputeShaderHashCodeGenerator>(), SourceText.From(source, Encoding.UTF8));
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする