-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Improve DisplayNameHelpers for NativeAOT #70084
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,11 @@ | |
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Reflection.Metadata; | ||
using System.Text; | ||
|
||
using Internal.TypeSystem; | ||
|
||
using Internal.TypeSystem.Ecma; | ||
using Debug = System.Diagnostics.Debug; | ||
|
||
namespace ILCompiler | ||
|
@@ -38,6 +39,12 @@ public static string GetDisplayName(this MethodDesc method) | |
{ | ||
sb.Append(method.OwningType.GetDisplayNameWithoutNamespace()); | ||
} | ||
else if (method.GetPropertyForAccessor() is PropertyPseudoDesc property) | ||
{ | ||
sb.Append(property.Name); | ||
sb.Append('.'); | ||
sb.Append(property.GetMethod.Name == method.Name ? "get" : "set"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we want to match C# syntax, should this also handle (Not necessary to fix in this PR.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created dotnet/linker#2816 to add this to linker/analyzer/aot (They are going to share tests soon, so we will need to do it in all 3). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it would be better to just standardize on however reflection displays these. This is the same issue as with interpreting ref/in/out in method signatures. C# tends to come up with new things every release. Do we want to be in a position where we need to play catch up, or in the position of reflection that just doesn't care? dotnet/linker#2158 (comment) (ref/in/out comment here) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I must admit I thought about it - but I was lazy to fix probably 100s of places in the linker tests to change this.
vitek-karas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
else | ||
{ | ||
sb.Append(method.Name); | ||
|
@@ -68,6 +75,20 @@ public static string GetDisplayName(this MethodDesc method) | |
return sb.ToString(); | ||
} | ||
|
||
public static string GetParameterDisplayName(this EcmaMethod method, int parameterIndex) | ||
{ | ||
var reader = method.MetadataReader; | ||
var methodDefinition = reader.GetMethodDefinition(method.Handle); | ||
foreach (var parameterHandle in methodDefinition.GetParameters()) | ||
{ | ||
var parameter = reader.GetParameter(parameterHandle); | ||
if (parameter.SequenceNumber == parameterIndex + 1) | ||
return reader.GetString(parameter.Name); | ||
} | ||
|
||
return $"#{parameterIndex}"; | ||
} | ||
|
||
public static string GetDisplayName(this FieldDesc field) | ||
{ | ||
return new StringBuilder(field.OwningType.GetDisplayName()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we tend to split
using Foo = ...
from the regular usings with a newline.