Generate input types as ReadOnlyMemory<T>
このコミットが含まれているのは:
1 親
077504566e
コミット
a6b87b551c
8ファイル変更
+268
-51
検索条件に一致するファイルはありません
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using Microsoft.CodeAnalysis;
|
||||
@@ -47,6 +48,17 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName,
|
||||
/// <param name="memberDeclarations">The member declarations to add to the generated type.</param>
|
||||
/// <returns>A <see cref="CompilationUnitSyntax"/> instance for the current hierarchy.</returns>
|
||||
public CompilationUnitSyntax GetSyntax(params MemberDeclarationSyntax[] memberDeclarations)
|
||||
{
|
||||
return GetSyntax(memberDeclarations, Array.Empty<MemberDeclarationSyntax>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="CompilationUnitSyntax"/> instance for the current hierarchy.
|
||||
/// </summary>
|
||||
/// <param name="memberDeclarations">The member declarations to add to the generated type.</param>
|
||||
/// <param name="additionalMemberDeclarations">Additional top-level member declarations, if any.</param>
|
||||
/// <returns>A <see cref="CompilationUnitSyntax"/> instance for the current hierarchy.</returns>
|
||||
public CompilationUnitSyntax GetSyntax(MemberDeclarationSyntax[] memberDeclarations, params MemberDeclarationSyntax[] additionalMemberDeclarations)
|
||||
{
|
||||
// Create the partial type declaration with for the current hierarchy.
|
||||
// This code produces a type declaration as follows:
|
||||
@@ -78,6 +90,8 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName,
|
||||
Comment("// <auto-generated/>"),
|
||||
Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true)));
|
||||
|
||||
CompilationUnitSyntax compilationUnitSyntax;
|
||||
|
||||
if (Namespace is "")
|
||||
{
|
||||
// If there is no namespace, attach the pragma directly to the declared type,
|
||||
@@ -85,24 +99,33 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName,
|
||||
//
|
||||
// <SYNTAX_TRIVIA>
|
||||
// <TYPE_HIERARCHY>
|
||||
return
|
||||
compilationUnitSyntax =
|
||||
CompilationUnit()
|
||||
.AddMembers(typeDeclarationSyntax.WithLeadingTrivia(syntaxTriviaList))
|
||||
.NormalizeWhitespace(eol: "\n");
|
||||
.AddMembers(typeDeclarationSyntax.WithLeadingTrivia(syntaxTriviaList));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create the compilation unit with disabled warnings, target namespace and generated type.
|
||||
// This will produce code as follows:
|
||||
//
|
||||
// <SYNTAX_TRIVIA>
|
||||
// namespace <NAMESPACE>;
|
||||
//
|
||||
// <TYPE_HIERARCHY>
|
||||
compilationUnitSyntax =
|
||||
CompilationUnit().AddMembers(
|
||||
FileScopedNamespaceDeclaration(IdentifierName(Namespace))
|
||||
.WithLeadingTrivia(syntaxTriviaList)
|
||||
.AddMembers(typeDeclarationSyntax));
|
||||
}
|
||||
|
||||
// Create the compilation unit with disabled warnings, target namespace and generated type.
|
||||
// This will produce code as follows:
|
||||
//
|
||||
// <SYNTAX_TRIVIA>
|
||||
// namespace <NAMESPACE>;
|
||||
//
|
||||
// <TYPE_HIERARCHY>
|
||||
return
|
||||
CompilationUnit().AddMembers(
|
||||
FileScopedNamespaceDeclaration(IdentifierName(Namespace))
|
||||
.WithLeadingTrivia(syntaxTriviaList)
|
||||
.AddMembers(typeDeclarationSyntax))
|
||||
.NormalizeWhitespace(eol: "\n");
|
||||
// Add any additional members, if any
|
||||
if (additionalMemberDeclarations.Length > 0)
|
||||
{
|
||||
compilationUnitSyntax = compilationUnitSyntax.AddMembers(additionalMemberDeclarations);
|
||||
}
|
||||
|
||||
// Normalize and return the tree
|
||||
return compilationUnitSyntax.NormalizeWhitespace(eol: "\n");
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする