Skip to content

Commit 689a122

Browse files
committed
Use GetDocumentationCommentId to specify single method
1 parent d40e809 commit 689a122

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

src/ConsoleAppFramework/Emitter.cs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ namespace ConsoleAppFramework;
55

66
internal class Emitter(DllReference? dllReference) // from EmitConsoleAppRun, null.
77
{
8-
private static readonly SymbolDisplayFormat DynamicDependencyContainingTypeFormat = new(
9-
globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included,
10-
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
11-
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
12-
miscellaneousOptions:
13-
SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers |
14-
SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier |
15-
SymbolDisplayMiscellaneousOptions.ExpandNullable
16-
);
17-
188
public void EmitRun(SourceBuilder sb, CommandWithId commandWithId, bool isRunAsync, string? methodName)
199
{
2010
var command = commandWithId.Command;
@@ -35,7 +25,7 @@ public void EmitRun(SourceBuilder sb, CommandWithId commandWithId, bool isRunAsy
3525
}
3626
var returnType = isRunAsync ? "async Task" : "void";
3727
var accessibility = !emitForBuilder ? "public static" : "private";
38-
methodName = methodName ?? (isRunAsync ? "RunAsync" : "Run");
28+
methodName ??= (isRunAsync ? "RunAsync" : "Run");
3929
var unsafeCode = (command.MethodKind == MethodKind.FunctionPointer) ? "unsafe " : "";
4030

4131
var commandMethodType = command.BuildDelegateSignature(commandWithId.BuildCustomDelegateTypeName(), out var delegateType);
@@ -64,14 +54,14 @@ public void EmitRun(SourceBuilder sb, CommandWithId commandWithId, bool isRunAsy
6454
command.Symbol.Value is IMethodSymbol dynamicDependencyMethod &&
6555
dynamicDependencyMethod.ContainingType != null)
6656
{
67-
var memberTypes = dynamicDependencyMethod.DeclaredAccessibility switch
68-
{
69-
Accessibility.Public or Accessibility.Protected or Accessibility.ProtectedOrInternal => "global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicMethods",
70-
_ => "global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicMethods"
71-
};
72-
73-
var containingType = dynamicDependencyMethod.ContainingType.ToDisplayString(DynamicDependencyContainingTypeFormat);
74-
dynamicDependencyAttribute = $"[global::System.Diagnostics.CodeAnalysis.DynamicDependency({memberTypes}, typeof({containingType}))]";
57+
var docCommentId = dynamicDependencyMethod.GetDocumentationCommentId();
58+
var parameterPartIndex = docCommentId?.IndexOf('(') ?? -1;
59+
var memberSignature = parameterPartIndex >= 0
60+
? dynamicDependencyMethod.Name + docCommentId!.Substring(parameterPartIndex)
61+
: dynamicDependencyMethod.Name;
62+
63+
var containingType = dynamicDependencyMethod.ContainingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
64+
dynamicDependencyAttribute = $"[global::System.Diagnostics.CodeAnalysis.DynamicDependency(\"{memberSignature}\", typeof({containingType}))]";
7565
}
7666

7767
if (!emitForBuilder)

0 commit comments

Comments
 (0)