Skip to content
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

Display init properties as ".init" in GetDisplayName #2855

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/linker/Linker/MethodDefinitionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,11 @@ public static void ClearDebugInformation (this MethodDefinition method)
di.Scope = null;
}
}

public static bool IsInit (this MethodDefinition methodDefinition)
{
return methodDefinition.IsSetter && methodDefinition.ReturnType.IsRequiredModifier
&& ((RequiredModifierType) methodDefinition.ReturnType).ModifierType.IsTypeOf ("System.Runtime.CompilerServices.IsExternalInit");
}
}
}
12 changes: 10 additions & 2 deletions src/linker/Linker/MethodReferenceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ public static string GetDisplayName (this MethodReference method)
var sb = new System.Text.StringBuilder ();

// Match C# syntaxis name if setter or getter
var methodDefinition = method.Resolve ();
MethodDefinition methodDefinition = method.Resolve ();
if (methodDefinition != null && (methodDefinition.IsSetter || methodDefinition.IsGetter)) {
// Append property name
string name = methodDefinition.IsSetter ? string.Concat (methodDefinition.Name.AsSpan (4), ".set") : string.Concat (methodDefinition.Name.AsSpan (4), ".get");
string name;
// Remove set_/get_ from beginning and add .get/.set/.init to end
if (methodDefinition.IsGetter)
name = string.Concat (methodDefinition.Name.AsSpan (4), ".get");
else if (methodDefinition.IsInit ())
name = string.Concat (methodDefinition.Name.AsSpan (4), ".init");
else
name = string.Concat (methodDefinition.Name.AsSpan (4), ".set");
jtschuster marked this conversation as resolved.
Show resolved Hide resolved

sb.Append (name);
// Insert declaring type name and namespace
sb.Insert (0, '.').Insert (0, method.DeclaringType.GetDisplayName ());
Expand Down
14 changes: 14 additions & 0 deletions test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,20 @@ public static void MethodWithPartiallyInstantiatedNestedGenericTypeArguments<Met
GenericClassMultipleParameters<MethodT, string>.NestedGenericClassMultipleParameters<int, MethodV> p)
{
}

public string Property {
[DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.Property.get")]
get;
[DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.Property.init")]
init;
}

public string Property2 {
[DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.Property2.get")]
get;
[DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.Property2.set")]
set;
}
}
}

Expand Down