Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ public bool IsCustomMappedWindowsRuntimeNonGenericInterfaceType(InteropReference
SignatureComparer.IgnoreVersion.Equals(type, interopReferences.IDisposable) ||
SignatureComparer.IgnoreVersion.Equals(type, interopReferences.IServiceProvider) ||
SignatureComparer.IgnoreVersion.Equals(type, interopReferences.ICommand) ||
SignatureComparer.IgnoreVersion.Equals(type, interopReferences.IEnumerable) ||
SignatureComparer.IgnoreVersion.Equals(type, interopReferences.IEnumerator) ||
SignatureComparer.IgnoreVersion.Equals(type, interopReferences.IList) ||
SignatureComparer.IgnoreVersion.Equals(type, interopReferences.INotifyCollectionChanged) ||
SignatureComparer.IgnoreVersion.Equals(type, interopReferences.INotifyDataErrorInfo) ||
SignatureComparer.IgnoreVersion.Equals(type, interopReferences.INotifyPropertyChanged);
Expand Down
13 changes: 11 additions & 2 deletions src/WinRT.Interop.Generator/Helpers/GuidGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,22 @@ public static Guid CreateIID(TypeSignature type, InteropReferences interopRefere
/// interfaces and, if necessary, the type's <see cref="System.Runtime.InteropServices.GuidAttribute"/>.
/// </summary>
/// <param name="type">The type descriptor to try to get the IID for.</param>
/// <param name="useWindowsUIXamlProjections">Whether to use <c>Windows.UI.Xaml</c> projections.</param>
/// <param name="interopReferences">The <see cref="InteropReferences"/> instance to use.</param>
/// <param name="iid">The resulting <see cref="Guid"/> value, if found.</param>
/// <returns>Whether <paramref name="iid"/> was succesfully retrieved.</returns>
public static bool TryGetIIDFromWellKnownInterfaceIIDsOrAttribute(ITypeDescriptor type, InteropReferences interopReferences, out Guid iid)
public static bool TryGetIIDFromWellKnownInterfaceIIDsOrAttribute(
ITypeDescriptor type,
bool useWindowsUIXamlProjections,
InteropReferences interopReferences,
out Guid iid)
{
// First try to get the IID from the custom-mapped types mapping
if (WellKnownInterfaceIIDs.TryGetGUID(type, interopReferences, out iid))
if (WellKnownInterfaceIIDs.TryGetGUID(
interfaceType: type,
useWindowsUIXamlProjections: useWindowsUIXamlProjections,
interopReferences: interopReferences,
guid: out iid))
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ internal partial class SignatureGenerator
private static string? GenericInstance(GenericInstanceTypeSignature typeSignature, InteropReferences interopReferences, bool useWindowsUIXamlProjections)
{
// If we fail to get the IID of the generic interface, we can't do anything else
if (!GuidGenerator.TryGetIIDFromWellKnownInterfaceIIDsOrAttribute(typeSignature.GenericType, interopReferences, out Guid interfaceIid))
if (!GuidGenerator.TryGetIIDFromWellKnownInterfaceIIDsOrAttribute(
type: typeSignature.GenericType,
useWindowsUIXamlProjections: useWindowsUIXamlProjections,
interopReferences: interopReferences,
iid: out Guid interfaceIid))
{
return null;
}
Expand Down Expand Up @@ -129,7 +133,11 @@ internal partial class SignatureGenerator
private static string? Delegate(TypeDefinition typeDefinition, InteropReferences interopReferences, bool useWindowsUIXamlProjections)
{
// Just like for generic instantiations, we need to resolve the IID for the type first
if (!GuidGenerator.TryGetIIDFromWellKnownInterfaceIIDsOrAttribute(typeDefinition, interopReferences, out Guid iid))
if (!GuidGenerator.TryGetIIDFromWellKnownInterfaceIIDsOrAttribute(
type: typeDefinition,
useWindowsUIXamlProjections: useWindowsUIXamlProjections,
interopReferences: interopReferences,
iid: out Guid iid))
{
return null;
}
Expand Down Expand Up @@ -159,7 +167,11 @@ internal partial class SignatureGenerator
}

// Otherwise, get the IID from the type definition and use it
if (!GuidGenerator.TryGetIIDFromWellKnownInterfaceIIDsOrAttribute(typeDefinition, interopReferences, out Guid iid))
if (!GuidGenerator.TryGetIIDFromWellKnownInterfaceIIDsOrAttribute(
type: typeDefinition,
useWindowsUIXamlProjections: useWindowsUIXamlProjections,
interopReferences: interopReferences,
iid: out Guid iid))
{
return null;
}
Expand All @@ -176,7 +188,11 @@ internal partial class SignatureGenerator
private static string? Interface(TypeDefinition typeDefinition, InteropReferences interopReferences, bool useWindowsUIXamlProjections)
{
// For all interface types, we should always be able to resolve their IID
if (!GuidGenerator.TryGetIIDFromWellKnownInterfaceIIDsOrAttribute(typeDefinition, interopReferences, out Guid iid))
if (!GuidGenerator.TryGetIIDFromWellKnownInterfaceIIDsOrAttribute(
type: typeDefinition,
useWindowsUIXamlProjections: useWindowsUIXamlProjections,
interopReferences: interopReferences,
iid: out Guid iid))
{
return null;
}
Expand Down Expand Up @@ -206,7 +222,11 @@ internal partial class SignatureGenerator
}

// Get the IID for 'Nullable<T>', which is the one we use for 'IReference<T>'
_ = WellKnownInterfaceIIDs.TryGetGUID(interopReferences.Nullable1, interopReferences, out Guid iid);
_ = WellKnownInterfaceIIDs.TryGetGUID(
interfaceType: interopReferences.Nullable1,
useWindowsUIXamlProjections: useWindowsUIXamlProjections,
interopReferences: interopReferences,
guid: out Guid iid);

// Construct the signature for the boxed delegate (the base type will be the possibly constructed delegate)
return $"pinterface({{{iid}}};{GetSignature(typeSignature.BaseType, interopReferences, useWindowsUIXamlProjections)})";
Expand Down
2 changes: 2 additions & 0 deletions src/WinRT.Interop.Generator/Helpers/TypeMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private readonly record struct MappedType(
new("System.ComponentModel.PropertyChangedEventHandler", new("Microsoft.UI.Xaml.Data", "PropertyChangedEventHandler")),
new("System.Windows.Input.ICommand", new("Microsoft.UI.Xaml.Input", "ICommand")),
new("System.Collections.IEnumerable", new("Microsoft.UI.Xaml.Interop", "IBindableIterable")),
new("System.Collections.IEnumerator", new("Microsoft.UI.Xaml.Interop", "IBindableIterator")),
new("System.Collections.IList", new("Microsoft.UI.Xaml.Interop", "IBindableVector")),
new("System.Collections.Specialized.INotifyCollectionChanged", new("Microsoft.UI.Xaml.Interop", "INotifyCollectionChanged")),
new("System.Collections.Specialized.NotifyCollectionChangedAction", new("Microsoft.UI.Xaml.Interop", "NotifyCollectionChangedAction", "enum(Microsoft.UI.Xaml.Interop.NotifyCollectionChangedAction;i4)")),
Expand Down Expand Up @@ -94,6 +95,7 @@ private readonly record struct MappedType(
new("Microsoft.UI.Xaml.Interop.NotifyCollectionChangedAction", new("Windows.UI.Xaml.Interop", "NotifyCollectionChangedAction", "enum(Windows.UI.Xaml.Interop.NotifyCollectionChangedAction;i4)")),
new("Microsoft.UI.Xaml.Interop.INotifyCollectionChanged", new("Windows.UI.Xaml.Interop", "INotifyCollectionChanged")),
new("Microsoft.UI.Xaml.Interop.IBindableIterable", new("Windows.UI.Xaml.Interop", "IBindableIterable")),
new("Microsoft.UI.Xaml.Interop.IBindableIterator", new("Windows.UI.Xaml.Interop", "IBindableIterator")),
new("Microsoft.UI.Xaml.Interop.IBindableVector", new("Windows.UI.Xaml.Interop", "IBindableVector")),
new("Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventHandler", new("Windows.UI.Xaml.Interop", "NotifyCollectionChangedEventHandler")),
new("Microsoft.UI.Xaml.Input.ICommand", new("Windows.UI.Xaml.Input", "ICommand")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public InteropReferences(
/// <summary>
/// Gets the <see cref="TypeReference"/> for <see cref="System.Windows.Input.ICommand"/>.
/// </summary>
public TypeReference ICommand => field ??= _corLibTypeFactory.CorLibScope.CreateTypeReference("System.Windows.Input"u8, "ICommand"u8);
public TypeReference ICommand => field ??= SystemObjectModel.CreateTypeReference("System.Windows.Input"u8, "ICommand"u8);

/// <summary>
/// Gets the <see cref="TypeReference"/> for <see cref="System.Collections.Specialized.INotifyCollectionChanged"/>.
Expand Down
57 changes: 46 additions & 11 deletions src/WinRT.Interop.Generator/References/WellKnownInterfaceIIDs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ internal static class WellKnownInterfaceIIDs
/// <returns>The <see cref="MemberReference"/> for the <c>get_IID_...</c> method for <paramref name="interfaceType"/>.</returns>
/// <exception cref="System.NullReferenceException"></exception>
/// <remarks>
/// The types handled by this method should be kept in sync with <see cref="WindowsRuntimeExtensions.IsCustomMappedWindowsRuntimeNonGenericInterfaceType"/>.
/// The types handled by this method should be kept in sync with
/// <see cref="WindowsRuntimeExtensions.IsCustomMappedWindowsRuntimeNonGenericInterfaceType"/> and
/// <see cref="WindowsRuntimeExtensions.IsManuallyProjectedWindowsRuntimeNonGenericInterfaceType"/>.
/// </remarks>
public static MemberReference get_IID(
ITypeDescriptor interfaceType,
Expand All @@ -80,14 +82,26 @@ public static MemberReference get_IID(
// Shared types
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IDisposable)
=> "Windows_Foundation_IClosable",
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IServiceProvider)
=> "Microsoft_UI_Xaml_IXamlServiceProvider",
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IAsyncInfo)
=> "Windows_Foundation_IAsyncInfo",
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IAsyncAction)
=> "Windows_Foundation_IAsyncAction",
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IVectorChangedEventArgs)
=> "Windows_Foundation_Collections_IVectorChangedEventArgs",

// XAML types
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IEnumerable) && useWindowsUIXamlProjections
=> "Windows_UI_Xaml_Interop_IBindableIterable",
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IEnumerable)
=> "Microsoft_UI_Xaml_Interop_IBindableIterable",
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IEnumerator) && useWindowsUIXamlProjections
=> "Windows_UI_Xaml_Interop_IBindableIterator",
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IEnumerator)
=> "Microsoft_UI_Xaml_Interop_IBindableIterator",
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IList) && useWindowsUIXamlProjections
=> "Windows_UI_Xaml_Interop_IBindableVector",
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IList)
=> "Microsoft_UI_Xaml_Interop_IBindableVector",
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.INotifyCollectionChanged) && useWindowsUIXamlProjections
=> "Windows_UI_Xaml_Interop_INotifyCollectionChanged",
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.INotifyCollectionChanged)
Expand All @@ -102,6 +116,8 @@ _ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.I
=> "Microsoft_UI_Xaml_Input_ICommand",
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.INotifyDataErrorInfo)
=> "Microsoft_UI_Xaml_Data_INotifyDataErrorInfo",
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IServiceProvider)
=> "Microsoft_UI_Xaml_IXamlServiceProvider",
_ => throw WellKnownInteropExceptions.InvalidCustomMappedTypeForWellKnownInterfaceIIDs(interfaceType)
};

Expand All @@ -115,16 +131,21 @@ _ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.I
/// Attempts to resolve a well-known Windows Runtime interface GUID for the specified type signature.
/// </summary>
/// <param name="interfaceType"> The <see cref="ITypeDescriptor"/> representing the managed type to inspect</param>
/// <param name="useWindowsUIXamlProjections">Whether to use <c>Windows.UI.Xaml</c> projections.</param>
/// <param name="interopReferences">The <see cref="InteropReferences"/> instance to use.</param>
/// <param name="guid">Out parameter for the resolved <see cref="Guid"/> of the type. </param>
/// <returns><c>true</c> if a matching GUID was found; otherwise, <c>false</c>.</returns>
public static bool TryGetGUID(
ITypeDescriptor interfaceType,
bool useWindowsUIXamlProjections,
InteropReferences interopReferences,
out Guid guid)
{
guid = interfaceType switch
{
// Shared types
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IDisposable)
=> new Guid("1BFCA4F6-2C4E-5174-9869-B39D35848FCC"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.EventHandler)
=> new Guid("9DE1C535-6AE1-11E0-84E1-18A905BCC53F"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.EventHandler1)
Expand All @@ -133,12 +154,8 @@ _ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.E
=> new Guid("9DE1C535-6AE1-11E0-84E1-18A905BCC53F"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.KeyValuePair2)
=> new Guid("02B51929-C1C4-4A7E-8940-0312B5C18500"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IEnumerable)
=> new Guid("FAA585EA-6214-4217-AFDA-7F46DE5869B3"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IEnumerable1)
=> new Guid("FAA585EA-6214-4217-AFDA-7F46DE5869B3"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IEnumerator)
=> new Guid("6A79E863-4300-459A-9966-CBB660963EE1"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IEnumerator1)
=> new Guid("6A79E863-4300-459A-9966-CBB660963EE1"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.AsyncOperationWithProgressCompletedHandler2)
Expand All @@ -147,8 +164,6 @@ _ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.A
=> new Guid("9D534225-231F-55E7-A6D0-6C938E2D9160"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.MapChangedEventHandler2)
=> new Guid("19046F0B-CF81-5DEC-BBB2-7CC250DA8B8B"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IList)
=> new Guid("393DE7DE-6FD0-4C0D-BB71-47244A113E93"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IList1)
=> new Guid("0E3F106F-A266-50A1-8043-C90FCF3844F6"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IReadOnlyList1)
Expand Down Expand Up @@ -179,8 +194,28 @@ _ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.A
=> new Guid("C261D8D0-71BA-5F38-A239-872342253A18"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IVectorChangedEventArgs)
=> new Guid("575933DF-34FE-4480-AF15-07691F3D5D9B"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IDisposable)
=> new Guid("1BFCA4F6-2C4E-5174-9869-B39D35848FCC"),

// XAML types
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IEnumerable)
=> new Guid("FAA585EA-6214-4217-AFDA-7F46DE5869B3"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IEnumerator)
=> new Guid("6A79E863-4300-459A-9966-CBB660963EE1"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IList)
=> new Guid("393DE7DE-6FD0-4C0D-BB71-47244A113E93"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.INotifyCollectionChanged) && useWindowsUIXamlProjections
=> new Guid("28B167D5-1A31-465B-9B25-D5C3AE686C40"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.INotifyCollectionChanged)
=> new Guid("530155E1-28A5-5693-87CE-30724D95A06D"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.INotifyPropertyChanged) && useWindowsUIXamlProjections
=> new Guid("CF75D69C-F2F4-486B-B302-BB4C09BAEBFA"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.INotifyPropertyChanged)
=> new Guid("90B17601-B065-586E-83D9-9ADC3A695284"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.ICommand)
=> new Guid("E5AF3542-CA67-4081-995B-709DD13792DF"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.INotifyDataErrorInfo)
=> new Guid("0EE6C2CC-273E-567D-BC0A-1DD87EE51EBA"),
_ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IServiceProvider)
=> new Guid("68B3A2DF-8173-539F-B524-C8A2348F5AFB"),
_ => Guid.Empty
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Runtime.InteropServices;
using Windows.Foundation.Metadata;
using WindowsRuntime;

Expand All @@ -11,6 +12,7 @@ namespace Windows.Foundation.Collections;
/// </summary>
/// <typeparam name="K">The type of keys in the map.</typeparam>
[WindowsRuntimeMetadata("Windows.Foundation.FoundationContract")]
[Guid("9939F4DF-050A-4C0F-AA60-77075F9C4777")]
[ContractVersion(typeof(FoundationContract), 65536u)]
public interface IMapChangedEventArgs<K>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Windows.Foundation.Metadata;
using WindowsRuntime;

Expand All @@ -14,6 +15,7 @@ namespace Windows.Foundation.Collections;
/// <typeparam name="K">The type of keys in the observable map.</typeparam>
/// <typeparam name="V">The type of values in the observable map.</typeparam>
[WindowsRuntimeMetadata("Windows.Foundation.FoundationContract")]
[Guid("65DF2BF5-BF39-41B5-AEBC-5A9D865E472B")]
[ContractVersion(typeof(FoundationContract), 65536u)]
public interface IObservableMap<K, V> : IDictionary<K, V>, ICollection<KeyValuePair<K, V>>, IEnumerable<KeyValuePair<K, V>>, IEnumerable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Windows.Foundation.Metadata;
using WindowsRuntime;

Expand All @@ -13,6 +14,7 @@ namespace Windows.Foundation.Collections;
/// </summary>
/// <typeparam name="T">The type of elements in the observable vector.</typeparam>
[WindowsRuntimeMetadata("Windows.Foundation.FoundationContract")]
[Guid("5917EB53-50B4-4A0D-B309-65862B3F1DBC")]
[ContractVersion(typeof(FoundationContract), 65536u)]
public interface IObservableVector<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable
{
Expand Down
Loading
Loading