Closed
Description
Follow up to #114455
In CsWinRT, we support both UWP XAML and WinUI 3 projections. For the most part, things "just work", since the various types from Windows.UI.Xaml.*
and Microsoft.UI.Xaml.*
are just projected normally, and they're not any different than any other Windows Runtime API. However, some custom mapped types are unfortunately "weird", in the sense that the same .NET types need to be mapped to different Windows Runtime APIs depending on which projection mode is used. This also means that the IID for the native object will be different. Because this is part of the ComInterfaceEntry
, we'd like for ILC to support folding this even though some of the IIDs in the entries depend on a feature switch.
In practice, we'd like ILC to be able to fold this:
public struct SomeTypeVtableEntries
{
public ComInterfaceEntry ISomeType;
public ComInterfaceEntry IStringable;
public ComInterfaceEntry IWeakReferenceSource;
public ComInterfaceEntry IMarshal;
public ComInterfaceEntry IAgileObject;
public ComInterfaceEntry IInspectable;
public ComInterfaceEntry IUnknown;
}
public static class SomeTypeImpl
{
[FixedAddressValueType]
private static readonly SomeTypeVtableEntries VtableEntries;
static SomeTypeImpl()
{
Entries.ISomeType.IID = IID; // <-- This one here
Entries.ISomeType.Vtable = PointReferenceImpl.AbiToProjectionVftablePtr;
Entries.IStringable.IID = WellKnownInterfaceIds.IID_IStringable;
Entries.IStringable.Vtable = IStringableImpl.AbiToProjectionVftablePtr;
// etc.
}
public static ref readonly Guid IID => ref WindowsRuntimeFeatureSwitches.UseWindowsUIXamlProjections
? ref IIDs.IID_WUX_ISomeType
: ref IIDs.IID_MUX_ISomeType;
}
internal static class IIDs
{
public static ref readonly Guid IID_WUX_ISomeType
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
ReadOnlySpan<byte> data = [0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x9A, 0xAB, 0xBC, 0xCD, 0xDE, 0xEF, 0xF0, 0x00];
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
}
}
public static ref readonly Guid IID_MUX_ISomeType
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
ReadOnlySpan<byte> data = [0xDE, 0xEF, 0xF0, 0x00, 0x9A, 0xAB, 0xBC, 0xCD, 0x56, 0x67, 0x78, 0x89, 0x12, 0x23, 0x34, 0x45];
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
}
}
}
internal static class WindowsRuntimeFeatureSwitches
{
[FeatureSwitchDefinition("CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS")]
public static bool UseWindowsUIXamlProjections { get; } = ...;
}
Metadata
Metadata
Assignees
Type
Projects
Status
No status