Skip to content

Commit

Permalink
Avoid display classes for enum stubs
Browse files Browse the repository at this point in the history
ff
  • Loading branch information
Sergio0694 committed Jan 23, 2024
1 parent 9958781 commit 1ad78a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/WinRT.Runtime/Marshalers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(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>(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
Expand Down Expand Up @@ -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<T>();
}
else
{
CopyAbi = Marshaler.CopyUIntEnum;
CopyManaged = Marshaler.CopyUIntEnum;
CopyAbi = Marshaler.CopyUIntEnumFunc;
CopyManaged = Marshaler.CopyUIntEnumDirectFunc.WithTypedT1<T>();
}
}
CreateMarshalerArray = (T[] array) => MarshalBlittable<T>.CreateMarshalerArray(array);
Expand Down
10 changes: 10 additions & 0 deletions src/cswinrt/strings/WinRT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public static Action<object> WithMarshaler2Support(this Action<IObjectReference>
return action.InvokeWithMarshaler2Support;
}

public static Action<T, IntPtr> WithTypedT1<T>(this Action<object, IntPtr> action)
{
return action.InvokeWithTypedT1;
}

public static Func<object, TResult> WithObjectT<T, TResult>(this Func<T, TResult> function)
{
return function.InvokeWithObjectT;
Expand Down Expand Up @@ -98,6 +103,11 @@ private static void InvokeWithObjectParams<T>(this Action<T> func, object arg)
{
func.Invoke((T)arg);
}

private static void InvokeWithTypedT1<T>(this Action<object, IntPtr> action, T arg1, IntPtr arg2)
{
action.Invoke(arg1, arg2);
}
}

internal sealed class Platform
Expand Down

0 comments on commit 1ad78a8

Please sign in to comment.