diff --git a/src/WinRT.Runtime/Marshalers.cs b/src/WinRT.Runtime/Marshalers.cs index d7f22eefa..92f3bd993 100644 --- a/src/WinRT.Runtime/Marshalers.cs +++ b/src/WinRT.Runtime/Marshalers.cs @@ -1677,11 +1677,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 @@ -1842,13 +1842,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 6d6cd9039..1b8e66a74 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