From 1ad78a8bf48abb5e40a1604e6832a6d242463d16 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 13 Jan 2024 17:42:21 +0100 Subject: [PATCH] Avoid display classes for enum stubs ff --- src/WinRT.Runtime/Marshalers.cs | 12 ++++++------ src/cswinrt/strings/WinRT.cs | 10 ++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/WinRT.Runtime/Marshalers.cs b/src/WinRT.Runtime/Marshalers.cs index e3be06b3c..7d2922a99 100644 --- a/src/WinRT.Runtime/Marshalers.cs +++ b/src/WinRT.Runtime/Marshalers.cs @@ -1712,11 +1712,11 @@ internal static class Marshaler internal static unsafe void CopyIntEnum(object value, IntPtr dest) => *(int*)dest.ToPointer() = (int)Convert.ChangeType(value, typeof(int)); - internal static unsafe void CopyIntEnum(T value, IntPtr dest) => *(int*)dest.ToPointer() = (int)(object)value; + internal static unsafe void CopyIntEnumDirect(object value, IntPtr dest) => *(int*)dest.ToPointer() = (int)value; internal static unsafe void CopyUIntEnum(object value, IntPtr dest) => *(uint*)dest.ToPointer() = (uint)Convert.ChangeType(value, typeof(uint)); - internal static unsafe void CopyUIntEnum(T value, IntPtr dest) => *(uint*)dest.ToPointer() = (uint)(object)value; + internal static unsafe void CopyUIntEnumDirect(object value, IntPtr dest) => *(uint*)dest.ToPointer() = (uint)value; } #if EMBED @@ -1904,13 +1904,13 @@ static Marshaler() // For marshaling non-blittable enum arrays via MarshalNonBlittable if (typeof(T).GetEnumUnderlyingType() == typeof(int)) { - CopyAbi = Marshaler.CopyIntEnum; - CopyManaged = Marshaler.CopyIntEnum; + CopyAbi = Marshaler.CopyIntEnumFunc; + CopyManaged = Marshaler.CopyIntEnumDirectFunc.WithTypedT1(); } else { - CopyAbi = Marshaler.CopyUIntEnum; - CopyManaged = Marshaler.CopyUIntEnum; + CopyAbi = Marshaler.CopyUIntEnumFunc; + CopyManaged = Marshaler.CopyUIntEnumDirectFunc.WithTypedT1(); } } CreateMarshalerArray = (T[] array) => MarshalBlittable.CreateMarshalerArray(array); diff --git a/src/cswinrt/strings/WinRT.cs b/src/cswinrt/strings/WinRT.cs index 430a13778..e9b84fa91 100644 --- a/src/cswinrt/strings/WinRT.cs +++ b/src/cswinrt/strings/WinRT.cs @@ -47,6 +47,11 @@ public static Action WithMarshaler2Support(this Action return action.InvokeWithMarshaler2Support; } + public static Action WithTypedT1(this Action action) + { + return action.InvokeWithTypedT1; + } + public static Func WithObjectT(this Func function) { return function.InvokeWithObjectT; @@ -98,6 +103,11 @@ private static void InvokeWithObjectParams(this Action func, object arg) { func.Invoke((T)arg); } + + private static void InvokeWithTypedT1(this Action action, T arg1, IntPtr arg2) + { + action.Invoke(arg1, arg2); + } } internal sealed class Platform