From e9a97ae87a636c9247b9469c256d51790cc53e6b Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Mon, 20 Jun 2022 16:32:32 -0500 Subject: [PATCH 1/5] Display init properties in GetDisplayName --- src/linker/Linker/MethodDefinitionExtensions.cs | 7 +++++++ src/linker/Linker/MethodReferenceExtensions.cs | 12 ++++++++++-- test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs | 12 ++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/linker/Linker/MethodDefinitionExtensions.cs b/src/linker/Linker/MethodDefinitionExtensions.cs index 814d390d845a..bc7a527aa676 100644 --- a/src/linker/Linker/MethodDefinitionExtensions.cs +++ b/src/linker/Linker/MethodDefinitionExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using Mono.Cecil; namespace Mono.Linker @@ -98,5 +99,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"); + } } } diff --git a/src/linker/Linker/MethodReferenceExtensions.cs b/src/linker/Linker/MethodReferenceExtensions.cs index e38371399780..a1baa6324827 100644 --- a/src/linker/Linker/MethodReferenceExtensions.cs +++ b/src/linker/Linker/MethodReferenceExtensions.cs @@ -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"); + sb.Append (name); // Insert declaring type name and namespace sb.Insert (0, '.').Insert (0, method.DeclaringType.GetDisplayName ()); diff --git a/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs b/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs index 1cdf6abf1ad9..d799a6dd5e6d 100644 --- a/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs +++ b/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs @@ -212,6 +212,18 @@ public static void MethodWithPartiallyInstantiatedNestedGenericTypeArguments.NestedGenericClassMultipleParameters 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; + } } } From 252306be03467eca499978f53a45bcb862d6cb6d Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Tue, 21 Jun 2022 09:27:16 -0500 Subject: [PATCH 2/5] formatting --- src/linker/Linker/MethodDefinitionExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/linker/Linker/MethodDefinitionExtensions.cs b/src/linker/Linker/MethodDefinitionExtensions.cs index bc7a527aa676..a47b415aadf9 100644 --- a/src/linker/Linker/MethodDefinitionExtensions.cs +++ b/src/linker/Linker/MethodDefinitionExtensions.cs @@ -103,7 +103,7 @@ public static void ClearDebugInformation (this MethodDefinition method) public static bool IsInit (this MethodDefinition methodDefinition) { return methodDefinition.IsSetter && methodDefinition.ReturnType.IsRequiredModifier - && ((RequiredModifierType)methodDefinition.ReturnType).ModifierType.IsTypeOf ("System.Runtime.CompilerServices.IsExternalInit"); + && ((RequiredModifierType) methodDefinition.ReturnType).ModifierType.IsTypeOf ("System.Runtime.CompilerServices.IsExternalInit"); } } } From 3009a6e4c72333cde0a18594c9a3e60c9dd7c297 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Tue, 21 Jun 2022 09:44:36 -0500 Subject: [PATCH 3/5] formatting --- test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs b/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs index d799a6dd5e6d..4f97a0d1f555 100644 --- a/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs +++ b/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs @@ -212,12 +212,14 @@ public static void MethodWithPartiallyInstantiatedNestedGenericTypeArguments.NestedGenericClassMultipleParameters 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; From a3188de04ba1bee76dfd7d515d1e288879665a19 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Tue, 21 Jun 2022 09:45:40 -0500 Subject: [PATCH 4/5] Remove using --- src/linker/Linker/MethodDefinitionExtensions.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/linker/Linker/MethodDefinitionExtensions.cs b/src/linker/Linker/MethodDefinitionExtensions.cs index a47b415aadf9..979c54e90591 100644 --- a/src/linker/Linker/MethodDefinitionExtensions.cs +++ b/src/linker/Linker/MethodDefinitionExtensions.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; using Mono.Cecil; namespace Mono.Linker From c594f89e10eb1964eadbf00cb8d10e66b16fb472 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Wed, 29 Jun 2022 09:27:26 -0500 Subject: [PATCH 5/5] Update MethodReferenceExtensions.cs --- src/linker/Linker/MethodReferenceExtensions.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/linker/Linker/MethodReferenceExtensions.cs b/src/linker/Linker/MethodReferenceExtensions.cs index a1baa6324827..a8da826c1d10 100644 --- a/src/linker/Linker/MethodReferenceExtensions.cs +++ b/src/linker/Linker/MethodReferenceExtensions.cs @@ -18,13 +18,14 @@ public static string GetDisplayName (this MethodReference method) if (methodDefinition != null && (methodDefinition.IsSetter || methodDefinition.IsGetter)) { // Append property name string name; - // Remove set_/get_ from beginning and add .get/.set/.init to end + // Remove set_/get_ prefix from method to get property name + var propertyName = methodDefinition.Name.AsSpan (4); if (methodDefinition.IsGetter) - name = string.Concat (methodDefinition.Name.AsSpan (4), ".get"); + name = string.Concat (propertyName, ".get"); else if (methodDefinition.IsInit ()) - name = string.Concat (methodDefinition.Name.AsSpan (4), ".init"); + name = string.Concat (propertyName, ".init"); else - name = string.Concat (methodDefinition.Name.AsSpan (4), ".set"); + name = string.Concat (propertyName, ".set"); sb.Append (name); // Insert declaring type name and namespace