Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
using System.Runtime.InteropServices;
using AsmResolver.DotNet;
using AsmResolver.DotNet.Code.Cil;
Expand Down Expand Up @@ -582,6 +583,39 @@ public static void ImplType(
ModuleDefinition module,
out TypeDefinition implType)
{
TypeSignature keyType = readOnlyDictionaryType.TypeArguments[0];
TypeSignature valueType = readOnlyDictionaryType.TypeArguments[1];

// Define the 'Lookup' method
MethodDefinition lookupMethod = InteropMethodDefinitionFactory.IReadOnlyDictionary2Impl.Lookup(
readOnlyDictionaryType: readOnlyDictionaryType,
lookupMethod: interopReferences.IReadOnlyDictionaryAdapter2Lookup(keyType, valueType),
interopReferences: interopReferences,
emitState: emitState,
module: module);

// Define the 'get_Size' method
MethodDefinition sizeMethod = InteropMethodDefinitionFactory.IReadOnlyDictionary2Impl.get_Size(
readOnlyDictionaryType: readOnlyDictionaryType,
sizeMethod: interopReferences.IReadOnlyDictionaryAdapter2Size(keyType, valueType),
interopReferences: interopReferences,
module: module);

// Define the 'HasKey' method
MethodDefinition hasKeymethod = InteropMethodDefinitionFactory.IReadOnlyDictionary2Impl.HasKey(
readOnlyDictionaryType: readOnlyDictionaryType,
hasKeyMethod: interopReferences.IReadOnlyDictionary2ContainsKey(keyType, valueType),
interopReferences: interopReferences,
emitState: emitState,
module: module);

// Define the 'Split' method
MethodDefinition splitMethod = InteropMethodDefinitionFactory.IReadOnlyDictionary2Impl.Split(
readOnlyDictionaryType: readOnlyDictionaryType,
interopReferences: interopReferences,
emitState: emitState,
module: module);

Impl(
interfaceType: ComInterfaceType.InterfaceIsIInspectable,
ns: InteropUtf8NameFactory.TypeNamespace(readOnlyDictionaryType),
Expand All @@ -591,7 +625,11 @@ public static void ImplType(
interopReferences: interopReferences,
module: module,
implType: out implType,
vtableMethods: []);
vtableMethods: [
lookupMethod,
sizeMethod,
hasKeymethod,
splitMethod]);

// Track the type (it may be needed by COM interface entries for user-defined types)
emitState.TrackTypeDefinition(implType, readOnlyDictionaryType, "Impl");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,22 @@ private static void TryTrackWindowsRuntimeGenericInterfaceTypeInstance(
discoveryState: discoveryState,
interopReferences: interopReferences,
module: module);

// Handle 'IReadOnlyDictionarySplitAdapter<TKey, TValue>', which is returned by the 'IMapView<K, V>.Split' method
TryTrackGenericTypeInstance(
typeSignature: interopReferences.IReadOnlyDictionarySplitAdapter2.MakeGenericReferenceType([.. typeSignature.TypeArguments]),
args: args,
discoveryState: discoveryState,
interopReferences: interopReferences,
module: module);

// Handle 'ArraySegment<T>.Enumerator', which is returned by 'IReadOnlyDictionarySplitAdapter<TKey, TValue>.GetEnumerator()'
TryTrackGenericTypeInstance(
typeSignature: interopReferences.ArraySegment1Enumerator.MakeGenericValueType(interopReferences.KeyValuePair2.MakeGenericValueType([.. typeSignature.TypeArguments])),
args: args,
discoveryState: discoveryState,
interopReferences: interopReferences,
module: module);
}
else if (SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.IObservableVector1))
{
Expand Down
11 changes: 11 additions & 0 deletions src/WinRT.Interop.Generator/Extensions/ImportExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ public static IMethodDefOrRef Import(this IMethodDefOrRef methodDefOrRef, Module
return (IMethodDefOrRef)methodDefOrRef.ImportWith(module.DefaultImporter);
}

/// <summary>
/// Imports a method descriptor or reference into a module using the default reference importer.
/// </summary>
/// <param name="methodDescriptor">The <see cref="IMethodDescriptor"/> instance to import.</param>
/// <param name="module">The module to import into.</param>
/// <returns>The imported <see cref="IMethodDescriptor"/>.</returns>
public static IMethodDescriptor Import(this IMethodDescriptor methodDescriptor, ModuleDefinition module)
{
return (IMethodDescriptor)methodDescriptor.ImportWith(module.DefaultImporter);
}

/// <summary>
/// Imports a type signature into a module using the default reference importer.
/// </summary>
Expand Down
Loading
Loading