diff --git a/src/WinRT.Runtime/Marshalers.cs b/src/WinRT.Runtime/Marshalers.cs index 7d2922a99..f4c7c4af0 100644 --- a/src/WinRT.Runtime/Marshalers.cs +++ b/src/WinRT.Runtime/Marshalers.cs @@ -1708,15 +1708,21 @@ public static T FromAbi(IntPtr nativeDelegate) internal static class Marshaler { - internal static Func ReturnParameterFunc = (object box) => box; + internal static readonly Func ReturnParameterFunc = ReturnParameter; + internal static readonly Action CopyIntEnumFunc = CopyIntEnum; + internal static readonly Action CopyIntEnumDirectFunc = CopyIntEnumDirect; + internal static readonly Action CopyUIntEnumFunc = CopyUIntEnum; + internal static readonly Action CopyUIntEnumDirectFunc = CopyUIntEnumDirect; - internal static unsafe void CopyIntEnum(object value, IntPtr dest) => *(int*)dest.ToPointer() = (int)Convert.ChangeType(value, typeof(int)); + private static object ReturnParameter(object arg) => arg; - internal static unsafe void CopyIntEnumDirect(object value, IntPtr dest) => *(int*)dest.ToPointer() = (int)value; + private static unsafe void CopyIntEnum(object value, IntPtr dest) => *(int*)dest.ToPointer() = (int)Convert.ChangeType(value, typeof(int)); - internal static unsafe void CopyUIntEnum(object value, IntPtr dest) => *(uint*)dest.ToPointer() = (uint)Convert.ChangeType(value, typeof(uint)); + private static unsafe void CopyIntEnumDirect(object value, IntPtr dest) => *(int*)dest.ToPointer() = (int)value; - internal static unsafe void CopyUIntEnumDirect(object value, IntPtr dest) => *(uint*)dest.ToPointer() = (uint)value; + private static unsafe void CopyUIntEnum(object value, IntPtr dest) => *(uint*)dest.ToPointer() = (uint)Convert.ChangeType(value, typeof(uint)); + + private static unsafe void CopyUIntEnumDirect(object value, IntPtr dest) => *(uint*)dest.ToPointer() = (uint)value; } #if EMBED