@@ -14,6 +14,7 @@ namespace PInvoke
14
14
using Microsoft . CodeAnalysis ;
15
15
using Microsoft . CodeAnalysis . CSharp ;
16
16
using Microsoft . CodeAnalysis . CSharp . Syntax ;
17
+ using static Microsoft . CodeAnalysis . CSharp . SyntaxFactory ;
17
18
18
19
/// <summary>
19
20
/// Generates <see cref="IntPtr"/> and/or <c>byte[]</c> overloads
@@ -103,12 +104,18 @@ from parameter in nativePointerParameters
103
104
}
104
105
}
105
106
107
+ var leadingTrivia = Trivia (
108
+ DocumentationCommentTrivia ( SyntaxKind . SingleLineDocumentationCommentTrivia ) . AddContent (
109
+ XmlText ( "/// " ) ,
110
+ XmlEmptyElement ( "inheritdoc" ) . AddAttributes ( XmlCrefAttribute ( NameMemberCref ( IdentifierName ( method . Identifier ) , ToCref ( method . ParameterList ) ) ) ) ,
111
+ XmlText ( ) . AddTextTokens ( XmlTextNewLine ( TriviaList ( ) , "\r \n " , "\r \n " , TriviaList ( ) ) ) ) ) ;
112
+
106
113
var transformedMethodBase = method
107
114
. WithReturnType ( TransformReturnType ( method . ReturnType ) )
108
115
. WithIdentifier ( TransformMethodName ( method ) )
109
116
. WithModifiers ( RemoveModifier ( method . Modifiers , SyntaxKind . ExternKeyword ) )
110
117
. WithAttributeLists ( FilterAttributes ( method . AttributeLists ) )
111
- . WithLeadingTrivia ( method . GetLeadingTrivia ( ) . Reverse ( ) . TakeWhile ( t => ! t . IsDirective ) . Reverse ( ) )
118
+ . WithLeadingTrivia ( leadingTrivia )
112
119
. WithTrailingTrivia ( method . GetTrailingTrivia ( ) . TakeWhile ( t => ! t . IsDirective ) )
113
120
. WithSemicolonToken ( SyntaxFactory . Token ( SyntaxKind . None ) )
114
121
. WithExpressionBody ( null ) ;
@@ -143,6 +150,15 @@ from parameter in nativePointerParameters
143
150
return Task . FromResult ( SyntaxFactory . SingletonList < MemberDeclarationSyntax > ( generatedType ) ) ;
144
151
}
145
152
153
+ private static CrefParameterListSyntax ToCref ( ParameterListSyntax parameterList ) => CrefParameterList ( ) . AddParameters ( parameterList . Parameters . Select ( ToCref ) . ToArray ( ) ) ;
154
+
155
+ private static CrefParameterSyntax ToCref ( ParameterSyntax parameter )
156
+ => CrefParameter (
157
+ parameter . Modifiers . Any ( SyntaxKind . RefKeyword ) ? Token ( SyntaxKind . RefKeyword ) :
158
+ parameter . Modifiers . Any ( SyntaxKind . OutKeyword ) ? Token ( SyntaxKind . OutKeyword ) :
159
+ default ,
160
+ parameter . Type ) ;
161
+
146
162
private static SyntaxList < AttributeListSyntax > FilterAttributes ( SyntaxList < AttributeListSyntax > attributeLists )
147
163
{
148
164
var result = SyntaxFactory . List < AttributeListSyntax > ( ) ;
0 commit comments