-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Set EndpointName and DisplayName given method name in endpoints #35439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9ff9267
Set EndpointName automatically from method name
captainsafia 704673f
Only support adding names from local functions
captainsafia c5fa42f
Supoort local functions via Roslyn parsing logic
captainsafia 8fb48c3
Set DisplayName using endpoint name
captainsafia 3de3976
Address code review and clean up parser
captainsafia 1e74031
Address feedback from Roslyn review
captainsafia 54ee5cd
Clean up type null validation
captainsafia 56c98a3
Fix scenario for local function
captainsafia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
// This code is a stop-gap and exists to address the issues with extracting | ||
// original method names from generated local functions. See https://github.com/dotnet/roslyn/issues/55651 | ||
// for more info. | ||
namespace Microsoft.CodeAnalysis.CSharp.Symbols | ||
{ | ||
internal static class GeneratedNameParser | ||
{ | ||
/// <summary> | ||
/// Parses generated local function name out of a generated method name. | ||
/// </summary> | ||
internal static bool TryParseLocalFunctionName(string generatedName, [NotNullWhen(true)] out string? originalName) | ||
{ | ||
originalName = null; | ||
|
||
var startIndex = generatedName.LastIndexOf(">g__", StringComparison.Ordinal); | ||
var endIndex = generatedName.LastIndexOf("|", StringComparison.Ordinal); | ||
if (startIndex >= 0 && endIndex >= 0 && endIndex - startIndex > 4) | ||
{ | ||
originalName = generatedName.Substring(startIndex + 4, endIndex - startIndex - 4); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Reflection; | ||
|
||
namespace System.Runtime.CompilerServices | ||
{ | ||
internal static class TypeHelper | ||
{ | ||
/// <summary> | ||
/// Checks to see if a given type is compiler generated. | ||
/// <remarks> | ||
/// The compiler will annotate either the target type or the declaring type | ||
/// with the CompilerGenerated attribute. We walk up the declaring types until | ||
/// we find a CompilerGenerated attribute or declare the type as not compiler | ||
/// generated otherwise. | ||
/// </remarks> | ||
/// </summary> | ||
/// <param name="type">The type to evaluate.</param> | ||
/// <returns><see langword="true" /> if <paramref name="type"/> is compiler generated.</returns> | ||
internal static bool IsCompilerGeneratedType(Type? type = null) | ||
{ | ||
if (type is not null) | ||
{ | ||
return Attribute.IsDefined(type, typeof(CompilerGeneratedAttribute)) || IsCompilerGeneratedType(type.DeclaringType); | ||
captainsafia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// Checks to see if a given method is compiler generated. | ||
/// </summary> | ||
/// <param name="method">The method to evaluate.</param> | ||
/// <returns><see langword="true" /> if <paramref name="method"/> is compiler generated.</returns> | ||
internal static bool IsCompilerGeneratedMethod(MethodInfo method) | ||
{ | ||
return Attribute.IsDefined(method, typeof(CompilerGeneratedAttribute)) || IsCompilerGeneratedType(method.DeclaringType); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.