diff --git a/src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IAsyncActionWithProgress1.cs b/src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IAsyncActionWithProgress1.cs new file mode 100644 index 000000000..ddb4b5997 --- /dev/null +++ b/src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IAsyncActionWithProgress1.cs @@ -0,0 +1,605 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using AsmResolver.DotNet; +using AsmResolver.DotNet.Signatures; +using AsmResolver.PE.DotNet.Metadata.Tables; +using WindowsRuntime.InteropGenerator.Factories; +using WindowsRuntime.InteropGenerator.Generation; +using WindowsRuntime.InteropGenerator.References; +using static AsmResolver.PE.DotNet.Cil.CilOpCodes; + +namespace WindowsRuntime.InteropGenerator.Builders; + +/// +internal partial class InteropTypeDefinitionBuilder +{ + /// + /// Helpers for Windows.Foundation.IAsyncActionWithProgress<TProgress> types. + /// + public static class IAsyncActionWithProgress1 + { + /// + /// Creates the 'IID' property for some Windows.Foundation.IAsyncActionWithProgress<TProgress> interface. + /// + /// The for the async action type. + /// The instance to use. + /// The instance to use. + /// The interop module being built. + /// The resulting 'IID' get method for . + public static void IID( + GenericInstanceTypeSignature actionType, + InteropDefinitions interopDefinitions, + InteropReferences interopReferences, + ModuleDefinition module, + out MethodDefinition get_IidMethod) + { + InteropTypeDefinitionBuilder.IID( + name: InteropUtf8NameFactory.TypeName(actionType), + interopDefinitions: interopDefinitions, + interopReferences: interopReferences, + module: module, + iid: Guid.NewGuid(), // TODO + out get_IidMethod); + } + + /// + /// Creates a new type definition for the methods for some Windows.Foundation.IAsyncActionWithProgress<TProgress> interface. + /// + /// The for the async action type. + /// The instance to use. + /// The instance to use. + /// The emit state for this invocation. + /// The interop module being built. + /// The resulting methods type. + public static void Methods( + GenericInstanceTypeSignature actionType, + InteropDefinitions interopDefinitions, + InteropReferences interopReferences, + InteropGeneratorEmitState emitState, + ModuleDefinition module, + out TypeDefinition actionMethodsType) + { + TypeSignature progressType = actionType.TypeArguments[0]; + + // We're declaring an 'internal static class' type + actionMethodsType = new TypeDefinition( + ns: InteropUtf8NameFactory.TypeNamespace(actionType), + name: InteropUtf8NameFactory.TypeName(actionType, "Methods"), + attributes: TypeAttributes.AutoLayout | TypeAttributes.Sealed | TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit, + baseType: module.CorLibTypeFactory.Object.ToTypeDefOrRef()) + { + Interfaces = { new InterfaceImplementation(interopReferences.IAsyncActionWithProgressMethodsImpl1.MakeGenericReferenceType(progressType).Import(module).ToTypeDefOrRef()) } + }; + + module.TopLevelTypes.Add(actionMethodsType); + + // Get the generated 'ConvertToManaged' method to marshal the 'AsyncActionProgressHandler' instance to managed + MethodDefinition progressConvertToManagedMethod = emitState.LookupTypeDefinition( + typeSignature: interopReferences.AsyncActionProgressHandler1.MakeGenericReferenceType(progressType), + key: "Marshaller").GetMethod("ConvertToManaged"u8); + + // Define the 'Progress' get method: + MethodDefinition get_ProgressMethod = InteropMethodDefinitionFactory.IAsyncInfoMethods.get_Handler( + methodName: "Progress"u8, + handlerType: interopReferences.AsyncActionProgressHandler1.MakeGenericReferenceType(progressType), + vftblField: interopDefinitions.IAsyncActionWithProgressVftbl.GetField("get_Progress"u8), + convertToManagedMethod: progressConvertToManagedMethod, + interopReferences: interopReferences, + module: module); + + actionMethodsType.AddMethodImplementation( + declaration: interopReferences.IAsyncActionWithProgressMethodsImpl1get_Progress(progressType).Import(module), + method: get_ProgressMethod); + + // Get the generated 'ConvertToUnmanaged' method to marshal the 'AsyncActionProgressHandler' instance to native + MethodDefinition progressConvertToUnmanagedMethod = emitState.LookupTypeDefinition( + typeSignature: interopReferences.AsyncActionProgressHandler1.MakeGenericReferenceType(progressType), + key: "Marshaller").GetMethod("ConvertToUnmanaged"u8); + + // Define the 'Progress' set method: + MethodDefinition set_ProgressMethod = InteropMethodDefinitionFactory.IAsyncInfoMethods.set_Handler( + methodName: "Progress"u8, + handlerType: interopReferences.AsyncActionProgressHandler1.MakeGenericReferenceType(progressType), + vftblField: interopDefinitions.IAsyncActionWithProgressVftbl.GetField("set_Progress"u8), + convertToUnmanagedMethod: progressConvertToUnmanagedMethod, + interopReferences: interopReferences, + module: module); + + actionMethodsType.AddMethodImplementation( + declaration: interopReferences.IAsyncActionWithProgressMethodsImpl1set_Progress(progressType).Import(module), + method: set_ProgressMethod); + + // Get the generated 'ConvertToManaged' method to marshal the 'AsyncActionWithProgressCompletedHandler' instance to managed + MethodDefinition completedConvertToManagedMethod = emitState.LookupTypeDefinition( + typeSignature: interopReferences.AsyncActionWithProgressCompletedHandler1.MakeGenericReferenceType(progressType), + key: "Marshaller").GetMethod("ConvertToManaged"u8); + + // Define the 'Completed' get method: + MethodDefinition get_CompletedMethod = InteropMethodDefinitionFactory.IAsyncInfoMethods.get_Handler( + methodName: "Completed"u8, + handlerType: interopReferences.AsyncActionWithProgressCompletedHandler1.MakeGenericReferenceType(progressType), + vftblField: interopDefinitions.IAsyncActionWithProgressVftbl.GetField("get_Completed"u8), + convertToManagedMethod: completedConvertToManagedMethod, + interopReferences: interopReferences, + module: module); + + actionMethodsType.AddMethodImplementation( + declaration: interopReferences.IAsyncActionWithProgressMethodsImpl1get_Completed(progressType).Import(module), + method: get_CompletedMethod); + + // Get the generated 'ConvertToUnmanaged' method to marshal the 'AsyncActionWithProgressCompletedHandler' instance to native + MethodDefinition completedConvertToUnmanagedMethod = emitState.LookupTypeDefinition( + typeSignature: interopReferences.AsyncActionWithProgressCompletedHandler1.MakeGenericReferenceType(progressType), + key: "Marshaller").GetMethod("ConvertToUnmanaged"u8); + + // Define the 'Completed' set method: + MethodDefinition set_CompletedMethod = InteropMethodDefinitionFactory.IAsyncInfoMethods.set_Handler( + methodName: "Completed"u8, + handlerType: interopReferences.AsyncActionWithProgressCompletedHandler1.MakeGenericReferenceType(progressType), + vftblField: interopDefinitions.IAsyncActionWithProgressVftbl.GetField("set_Completed"u8), + convertToUnmanagedMethod: completedConvertToUnmanagedMethod, + interopReferences: interopReferences, + module: module); + + actionMethodsType.AddMethodImplementation( + declaration: interopReferences.IAsyncActionWithProgressMethodsImpl1set_Completed(progressType).Import(module), + method: set_CompletedMethod); + + // Define the 'GetResults' method as follows: + // + // public static void GetResults(WindowsRuntimeObjectReference thisReference) + MethodDefinition getResultsMethod = new( + name: "GetResults"u8, + attributes: MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Static, + signature: MethodSignature.CreateStatic( + returnType: module.CorLibTypeFactory.Void, + parameterTypes: [interopReferences.WindowsRuntimeObjectReference.Import(module).ToReferenceTypeSignature()])) + { + CilInstructions = + { + { Ldarg_0 }, + { Call, interopReferences.IAsyncActionWithProgressGetResults.Import(module) }, + { Ret } + } + }; + + actionMethodsType.AddMethodImplementation( + declaration: interopReferences.IAsyncActionWithProgressMethodsImpl1GetResults(progressType).Import(module), + method: getResultsMethod); + } + + /// + /// Creates a new type definition for the native object for some Windows.Foundation.IAsyncActionWithProgress<TProgress> interface. + /// + /// The for the async action type. + /// The instance returned by . + /// The instance to use. + /// The interop module being built. + /// The resulting native object type. + public static void NativeObject( + GenericInstanceTypeSignature actionType, + TypeDefinition actionMethodsType, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition nativeObjectType) + { + // The 'NativeObject' is deriving from 'WindowsRuntimeAsyncActionWithProgress<, >' + TypeSignature windowsRuntimeAsyncActionWithProgress1Type = interopReferences.WindowsRuntimeAsyncActionWithProgress2.MakeGenericReferenceType( + actionType.TypeArguments[0], + actionMethodsType.ToReferenceTypeSignature()); + + InteropTypeDefinitionBuilder.NativeObject( + typeSignature: actionType, + nativeObjectBaseType: windowsRuntimeAsyncActionWithProgress1Type, + interopReferences: interopReferences, + module: module, + out nativeObjectType); + } + + /// + /// Creates a new type definition for the implementation of the IWindowsRuntimeUnsealedObjectComWrappersCallback interface for some IAsyncActionWithProgress<TProgress> interface. + /// + /// The for the async action type. + /// The type returned by . + /// The 'IID' get method for . + /// The instance to use. + /// The interop module being built. + /// The resulting callback type. + public static void ComWrappersCallbackType( + TypeSignature actionType, + TypeDefinition nativeObjectType, + MethodDefinition get_IidMethod, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition callbackType) + { + ComWrappersCallback( + runtimeClassName: actionType.FullName, // TODO + typeSignature: actionType, + nativeObjectType: nativeObjectType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + out callbackType); + } + + /// + /// Creates a new type definition for the marshaller attribute of some IAsyncActionWithProgress<TProgress> interface. + /// + /// The for the async action type. + /// The type returned by . + /// The 'IID' get method for . + /// The instance to use. + /// The module that will contain the type being created. + /// The resulting marshaller type. + public static void ComWrappersMarshallerAttribute( + GenericInstanceTypeSignature actionType, + TypeDefinition nativeObjectType, + MethodDefinition get_IidMethod, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition marshallerType) + { + InteropTypeDefinitionBuilder.ComWrappersMarshallerAttribute( + typeSignature: actionType, + nativeObjectType: nativeObjectType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + out marshallerType); + } + + /// + /// Creates a new type definition for the marshaller of some IAsyncActionWithProgress<TProgress> interface. + /// + /// The for the async action type. + /// The instance returned by . + /// The 'IID' get method for . + /// The instance to use. + /// The module that will contain the type being created. + /// The resulting marshaller type. + public static void Marshaller( + GenericInstanceTypeSignature actionType, + TypeDefinition operationComWrappersCallbackType, + MethodDefinition get_IidMethod, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition marshallerType) + { + InteropTypeDefinitionBuilder.Marshaller( + typeSignature: actionType, + interfaceComWrappersCallbackType: operationComWrappersCallbackType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + out marshallerType); + } + + /// + /// Creates a new type definition for the interface implementation of some IAsyncActionWithProgress<TProgress> interface. + /// + /// The for the async action type. + /// The instance returned by . + /// The instance to use. + /// The module that will contain the type being created. + /// The resulting interface implementation type. + public static void InterfaceImpl( + GenericInstanceTypeSignature actionType, + TypeDefinition actionMethodsType, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition interfaceImplType) + { + TypeSignature progressType = actionType.TypeArguments[0]; + + // We're declaring an 'internal interface class' type + interfaceImplType = new( + ns: InteropUtf8NameFactory.TypeNamespace(actionType), + name: InteropUtf8NameFactory.TypeName(actionType, "InterfaceImpl"), + attributes: TypeAttributes.Interface | TypeAttributes.AutoLayout | TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit, + baseType: null) + { + CustomAttributes = { new CustomAttribute(interopReferences.DynamicInterfaceCastableImplementationAttribute_ctor.Import(module)) }, + Interfaces = + { + new InterfaceImplementation(actionType.Import(module).ToTypeDefOrRef()), + new InterfaceImplementation(interopReferences.IAsyncInfo.Import(module)) + } + }; + + module.TopLevelTypes.Add(interfaceImplType); + + // Get the getter and setter accessor methods for 'Progress' + MethodDefinition[] progressMethods = actionMethodsType.GetMethods("Progress"u8); + + // Create the 'get_Progress' getter method + MethodDefinition get_ProgressMethod = new( + name: $"Windows.Foundation.IAsyncActionWithProgress<{progressType.FullName}>.get_Progress", + attributes: WellKnownMethodAttributesFactory.ExplicitInterfaceImplementationInstanceAccessorMethod, + signature: MethodSignature.CreateInstance(interopReferences.AsyncActionProgressHandler1.MakeGenericReferenceType(progressType).Import(module))); + + // Add and implement the 'get_Progress' method + interfaceImplType.AddMethodImplementation( + declaration: interopReferences.IAsyncActionWithProgress1get_Progress(progressType).Import(module), + method: get_ProgressMethod); + + // Create a body for the 'get_Progress' method + get_ProgressMethod.CilMethodBody = WellKnownCilMethodBodyFactory.DynamicInterfaceCastableImplementation( + interfaceType: actionType, + implementationMethod: get_ProgressMethod, + forwardedMethod: progressMethods[0], + interopReferences: interopReferences, + module: module); + + // Create the 'set_Progress' getter method + MethodDefinition set_ProgressMethod = new( + name: $"Windows.Foundation.IAsyncActionWithProgress<{progressType.FullName}>.set_Progress", + attributes: WellKnownMethodAttributesFactory.ExplicitInterfaceImplementationInstanceAccessorMethod, + signature: MethodSignature.CreateInstance( + returnType: module.CorLibTypeFactory.Void, + parameterTypes: [interopReferences.AsyncActionProgressHandler1.MakeGenericReferenceType(progressType).Import(module)])); + + // Add and implement the 'set_Progress' method + interfaceImplType.AddMethodImplementation( + declaration: interopReferences.IAsyncActionWithProgress1set_Progress(progressType).Import(module), + method: set_ProgressMethod); + + // Create a body for the 'set_Progress' method + set_ProgressMethod.CilMethodBody = WellKnownCilMethodBodyFactory.DynamicInterfaceCastableImplementation( + interfaceType: actionType, + implementationMethod: set_ProgressMethod, + forwardedMethod: progressMethods[1], + interopReferences: interopReferences, + module: module); + + // Create the 'Progress' property + PropertyDefinition progressProperty = new( + name: $"Windows.Foundation.IAsyncActionWithProgress<{progressType.FullName}>.Progress", + attributes: PropertyAttributes.None, + signature: PropertySignature.FromGetMethod(get_ProgressMethod)) + { + GetMethod = get_ProgressMethod, + SetMethod = set_ProgressMethod + }; + + interfaceImplType.Properties.Add(progressProperty); + + // Get the getter and setter accessor methods for 'Completed' + MethodDefinition[] completedMethods = actionMethodsType.GetMethods("Completed"u8); + + // Create the 'get_Completed' getter method + MethodDefinition get_CompletedMethod = new( + name: $"Windows.Foundation.IAsyncActionWithProgress<{progressType.FullName}>.get_Completed", + attributes: WellKnownMethodAttributesFactory.ExplicitInterfaceImplementationInstanceAccessorMethod, + signature: MethodSignature.CreateInstance(interopReferences.AsyncActionWithProgressCompletedHandler1.MakeGenericReferenceType(progressType).Import(module))); + + // Add and implement the 'get_Completed' method + interfaceImplType.AddMethodImplementation( + declaration: interopReferences.IAsyncActionWithProgress1get_Completed(progressType).Import(module), + method: get_CompletedMethod); + + // Create a body for the 'get_Completed' method + get_CompletedMethod.CilMethodBody = WellKnownCilMethodBodyFactory.DynamicInterfaceCastableImplementation( + interfaceType: actionType, + implementationMethod: get_CompletedMethod, + forwardedMethod: completedMethods[0], + interopReferences: interopReferences, + module: module); + + // Create the 'set_Completed' setter method + MethodDefinition set_CompletedMethod = new( + name: $"Windows.Foundation.IAsyncActionWithProgress<{progressType.FullName}>.set_Completed", + attributes: WellKnownMethodAttributesFactory.ExplicitInterfaceImplementationInstanceAccessorMethod, + signature: MethodSignature.CreateInstance( + returnType: module.CorLibTypeFactory.Void, + parameterTypes: [interopReferences.AsyncActionWithProgressCompletedHandler1.MakeGenericReferenceType(progressType).Import(module)])); + + // Add and implement the 'set_Completed' method + interfaceImplType.AddMethodImplementation( + declaration: interopReferences.IAsyncActionWithProgress1set_Completed(progressType).Import(module), + method: set_CompletedMethod); + + // Create a body for the 'set_Completed' method + set_CompletedMethod.CilMethodBody = WellKnownCilMethodBodyFactory.DynamicInterfaceCastableImplementation( + interfaceType: actionType, + implementationMethod: set_CompletedMethod, + forwardedMethod: completedMethods[1], + interopReferences: interopReferences, + module: module); + + // Create the 'Completed' property + PropertyDefinition completedProperty = new( + name: $"Windows.Foundation.IAsyncActionWithProgress<{progressType.FullName}>.Completed", + attributes: PropertyAttributes.None, + signature: PropertySignature.FromGetMethod(get_CompletedMethod)) + { + GetMethod = get_CompletedMethod, + SetMethod = set_CompletedMethod + }; + + interfaceImplType.Properties.Add(completedProperty); + + // Create the 'GetResults' method + MethodDefinition getResultsMethod = new( + name: $"Windows.Foundation.IAsyncActionWithProgress<{progressType.FullName}>.GetResults", + attributes: WellKnownMethodAttributesFactory.ExplicitInterfaceImplementationInstanceMethod, + signature: MethodSignature.CreateInstance(module.CorLibTypeFactory.Void)); + + // Add and implement the 'GetResults' method + interfaceImplType.AddMethodImplementation( + declaration: interopReferences.IAsyncActionWithProgress1GetResults(progressType).Import(module), + method: getResultsMethod); + + // Create a body for the 'GetResults' method + getResultsMethod.CilMethodBody = WellKnownCilMethodBodyFactory.DynamicInterfaceCastableImplementation( + interfaceType: actionType, + implementationMethod: getResultsMethod, + forwardedMethod: actionMethodsType.GetMethod("GetResults"u8), + interopReferences: interopReferences, + module: module); + } + + /// + /// Creates a new type definition for the implementation of the vtable for some IAsyncActionWithProgress<TProgress> interface. + /// + /// The for the async action type. + /// The instance to use. + /// The instance to use. + /// The emit state for this invocation. + /// The interop module being built. + /// The resulting implementation type. + public static void ImplType( + GenericInstanceTypeSignature actionType, + InteropDefinitions interopDefinitions, + InteropReferences interopReferences, + InteropGeneratorEmitState emitState, + ModuleDefinition module, + out TypeDefinition implType) + { + TypeSignature progressType = actionType.TypeArguments[0]; + + // Prepare the 'AsyncActionProgressHandler<>' signature + TypeSignature asyncActionProgressHandlerType = interopReferences.AsyncActionProgressHandler1.MakeGenericReferenceType(progressType); + + // Get the generated 'ConvertToUnmanaged' method to marshal the 'AsyncActionProgressHandler' instance to native + MethodDefinition progressConvertToUnmanagedMethod = emitState.LookupTypeDefinition( + typeSignature: asyncActionProgressHandlerType, + key: "Marshaller").GetMethod("ConvertToUnmanaged"u8); + + MethodDefinition get_ProgressMethod = InteropMethodDefinitionFactory.IAsyncInfoImpl.get_Handler( + methodName: "get_Progress"u8, + asyncInfoType: actionType, + handlerType: asyncActionProgressHandlerType, + get_HandlerMethod: interopReferences.IAsyncActionWithProgress1get_Progress(progressType), + convertToUnmanagedMethod: progressConvertToUnmanagedMethod, + interopReferences: interopReferences, + module: module); + + // Get the generated 'ConvertToManaged' method to marshal the 'AsyncOperationProgressHandler' instance to managed + MethodDefinition progressConvertToManagedMethod = emitState.LookupTypeDefinition( + typeSignature: asyncActionProgressHandlerType, + key: "Marshaller").GetMethod("ConvertToManaged"u8); + + MethodDefinition set_ProgressMethod = InteropMethodDefinitionFactory.IAsyncInfoImpl.set_Handler( + methodName: "set_Progress"u8, + asyncInfoType: actionType, + handlerType: asyncActionProgressHandlerType, + set_HandlerMethod: interopReferences.IAsyncActionWithProgress1set_Progress(progressType), + convertToManagedMethod: progressConvertToManagedMethod, + interopReferences: interopReferences, + module: module); + + // Prepare the 'AsyncActionWithProgressCompletedHandler<>' signature + TypeSignature asyncActionWithProgressCompletedHandlerType = interopReferences.AsyncActionWithProgressCompletedHandler1.MakeGenericReferenceType(progressType); + + // Get the generated 'ConvertToUnmanaged' method to marshal the 'AsyncActionProgressHandler' instance to native + MethodDefinition completedConvertToUnmanagedMethod = emitState.LookupTypeDefinition( + typeSignature: asyncActionWithProgressCompletedHandlerType, + key: "Marshaller").GetMethod("ConvertToUnmanaged"u8); + + MethodDefinition get_CompletedMethod = InteropMethodDefinitionFactory.IAsyncInfoImpl.get_Handler( + methodName: "get_Completed"u8, + asyncInfoType: actionType, + handlerType: asyncActionWithProgressCompletedHandlerType, + get_HandlerMethod: interopReferences.IAsyncActionWithProgress1get_Completed(progressType), + convertToUnmanagedMethod: completedConvertToUnmanagedMethod, + interopReferences: interopReferences, + module: module); + + // Get the generated 'ConvertToManaged' method to marshal the 'AsyncActionWithProgressCompletedHandler' instance to managed + MethodDefinition completedConvertToManagedMethod = emitState.LookupTypeDefinition( + typeSignature: asyncActionWithProgressCompletedHandlerType, + key: "Marshaller").GetMethod("ConvertToManaged"u8); + + MethodDefinition set_CompletedMethod = InteropMethodDefinitionFactory.IAsyncInfoImpl.set_Handler( + methodName: "set_Completed"u8, + asyncInfoType: actionType, + handlerType: asyncActionWithProgressCompletedHandlerType, + set_HandlerMethod: interopReferences.IAsyncActionWithProgress1set_Completed(progressType), + convertToManagedMethod: completedConvertToManagedMethod, + interopReferences: interopReferences, + module: module); + + MethodDefinition getResultsMethod = InteropMethodDefinitionFactory.IAsyncActionWithProgress1Impl.GetResults( + actionType: actionType, + interopReferences: interopReferences, + module: module); + + Impl( + interfaceType: ComInterfaceType.InterfaceIsIInspectable, + ns: InteropUtf8NameFactory.TypeNamespace(actionType), + name: InteropUtf8NameFactory.TypeName(actionType, "Impl"), + vftblType: interopDefinitions.IAsyncActionWithProgressVftbl, + interopDefinitions: interopDefinitions, + interopReferences: interopReferences, + module: module, + implType: out implType, + vtableMethods: [ + get_ProgressMethod, + set_ProgressMethod, + get_CompletedMethod, + set_CompletedMethod, + getResultsMethod]); + + // Track the type (it may be needed by COM interface entries for user-defined types) + emitState.TrackTypeDefinition(implType, actionType, "Impl"); + } + + /// + /// Creates a new type definition for the proxy type of some IAsyncActionWithProgress<TProgress> interface. + /// + /// The for the async action type. + /// The instance returned by . + /// The instance to use. + /// The module that will contain the type being created. + /// The resulting proxy type. + public static void Proxy( + GenericInstanceTypeSignature actionType, + TypeDefinition actionComWrappersMarshallerAttributeType, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition proxyType) + { + string runtimeClassName = $"Windows.Foundation.IAsyncActionWithProgress`1<{actionType.TypeArguments[0]}>"; // TODO + + InteropTypeDefinitionBuilder.Proxy( + ns: InteropUtf8NameFactory.TypeNamespace(actionType), + name: InteropUtf8NameFactory.TypeName(actionType), + runtimeClassName: runtimeClassName, + comWrappersMarshallerAttributeType: actionComWrappersMarshallerAttributeType, + interopReferences: interopReferences, + module: module, + out proxyType); + } + + /// + /// Creates the type map attributes for some IAsyncActionWithProgress<TProgress> interface. + /// + /// The for the async action type. + /// The instance returned by . + /// The instance returned by . + /// The instance to use. + /// The module that will contain the type being created. + public static void TypeMapAttributes( + GenericInstanceTypeSignature actionType, + TypeDefinition proxyType, + TypeDefinition interfaceImplType, + InteropReferences interopReferences, + ModuleDefinition module) + { + InteropTypeDefinitionBuilder.TypeMapAttributes( + runtimeClassName: $"Windows.Foundation.IAsyncActionWithProgress`1<{actionType.TypeArguments[0]}>", // TODO + externalTypeMapTargetType: proxyType.ToReferenceTypeSignature(), + externalTypeMapTrimTargetType: actionType, + proxyTypeMapSourceType: null, + proxyTypeMapProxyType: null, + interfaceTypeMapSourceType: actionType, + interfaceTypeMapProxyType: interfaceImplType.ToReferenceTypeSignature(), + interopReferences: interopReferences, + module: module); + } + } +} diff --git a/src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IAsyncOperation1.cs b/src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IAsyncOperation1.cs new file mode 100644 index 000000000..191b30f8f --- /dev/null +++ b/src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IAsyncOperation1.cs @@ -0,0 +1,465 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using AsmResolver.DotNet; +using AsmResolver.DotNet.Signatures; +using AsmResolver.PE.DotNet.Metadata.Tables; +using WindowsRuntime.InteropGenerator.Factories; +using WindowsRuntime.InteropGenerator.Generation; +using WindowsRuntime.InteropGenerator.References; + +namespace WindowsRuntime.InteropGenerator.Builders; + +/// +internal partial class InteropTypeDefinitionBuilder +{ + /// + /// Helpers for Windows.Foundation.IAsyncOperation1<TResult> types. + /// + public static class IAsyncOperation1 + { + /// + /// Creates the 'IID' property for some IAsyncOperation1<TResult> interface. + /// + /// The for the async operation type. + /// The instance to use. + /// The instance to use. + /// The interop module being built. + /// The resulting 'IID' get method for . + public static void IID( + GenericInstanceTypeSignature operationType, + InteropDefinitions interopDefinitions, + InteropReferences interopReferences, + ModuleDefinition module, + out MethodDefinition get_IidMethod) + { + InteropTypeDefinitionBuilder.IID( + name: InteropUtf8NameFactory.TypeName(operationType), + interopDefinitions: interopDefinitions, + interopReferences: interopReferences, + module: module, + iid: Guid.NewGuid(), // TODO + out get_IidMethod); + } + + /// + /// Creates a new type definition for the methods for some IAsyncOperation1<TResult> interface. + /// + /// The for the async operation type. + /// The instance to use. + /// The instance to use. + /// The emit state for this invocation. + /// The interop module being built. + /// The resulting methods type. + public static void Methods( + GenericInstanceTypeSignature operationType, + InteropDefinitions interopDefinitions, + InteropReferences interopReferences, + InteropGeneratorEmitState emitState, + ModuleDefinition module, + out TypeDefinition operationMethodsType) + { + TypeSignature resultType = operationType.TypeArguments[0]; + + // We're declaring an 'internal static class' type + operationMethodsType = new TypeDefinition( + ns: InteropUtf8NameFactory.TypeNamespace(operationType), + name: InteropUtf8NameFactory.TypeName(operationType, "Methods"), + attributes: TypeAttributes.AutoLayout | TypeAttributes.Sealed | TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit, + baseType: module.CorLibTypeFactory.Object.ToTypeDefOrRef()) + { + Interfaces = { new InterfaceImplementation(interopReferences.IAsyncOperationMethodsImpl1.MakeGenericReferenceType(resultType).Import(module).ToTypeDefOrRef()) } + }; + + module.TopLevelTypes.Add(operationMethodsType); + + // Get the generated 'ConvertToManaged' method to marshal the 'AsyncOperationCompletedHandler' instance to managed + MethodDefinition convertToManagedMethod = emitState.LookupTypeDefinition( + typeSignature: interopReferences.AsyncOperationCompletedHandler1.MakeGenericReferenceType(resultType), + key: "Marshaller").GetMethod("ConvertToManaged"u8); + + // Define the 'Completed' get method: + MethodDefinition get_CompletedMethod = InteropMethodDefinitionFactory.IAsyncInfoMethods.get_Handler( + methodName: "Completed"u8, + handlerType: interopReferences.AsyncOperationCompletedHandler1.MakeGenericReferenceType(resultType), + vftblField: interopDefinitions.IAsyncOperationVftbl.GetField("get_Completed"u8), + convertToManagedMethod: convertToManagedMethod, + interopReferences: interopReferences, + module: module); + + operationMethodsType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperationMethodsImpl1get_Completed(resultType).Import(module), + method: get_CompletedMethod); + + // Get the generated 'ConvertToUnmanaged' method to marshal the 'AsyncOperationCompletedHandler' instance to native + MethodDefinition convertToUnmanagedMethod = emitState.LookupTypeDefinition( + typeSignature: interopReferences.AsyncOperationCompletedHandler1.MakeGenericReferenceType(resultType), + key: "Marshaller").GetMethod("ConvertToUnmanaged"u8); + + // Define the 'Completed' set method: + MethodDefinition set_CompletedMethod = InteropMethodDefinitionFactory.IAsyncInfoMethods.set_Handler( + methodName: "Completed"u8, + handlerType: interopReferences.AsyncOperationCompletedHandler1.MakeGenericReferenceType(resultType), + vftblField: interopDefinitions.IAsyncOperationVftbl.GetField("set_Completed"u8), + convertToUnmanagedMethod: convertToUnmanagedMethod, + interopReferences: interopReferences, + module: module); + + operationMethodsType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperationMethodsImpl1set_Completed(resultType).Import(module), + method: set_CompletedMethod); + + // Define the 'GetResults' method: + MethodDefinition getResultsMethod = InteropMethodDefinitionFactory.IAsyncInfoMethods.GetResults( + resultType: resultType, + vftblField: interopDefinitions.IAsyncOperationVftbl.GetField("GetResults"u8), + interopReferences: interopReferences, + module: module); + + operationMethodsType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperationMethodsImpl1GetResults(resultType).Import(module), + method: getResultsMethod); + } + + /// + /// Creates a new type definition for the native object for some IAsyncOperation1<TResult> interface. + /// + /// The for the async operation type. + /// The instance returned by . + /// The instance to use. + /// The interop module being built. + /// The resulting native object type. + public static void NativeObject( + GenericInstanceTypeSignature operationType, + TypeDefinition operationMethodsType, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition nativeObjectType) + { + // The 'NativeObject' is deriving from 'WindowsRuntimeAsyncOperation<, >' + TypeSignature windowsRuntimeAsyncOperation1Type = interopReferences.WindowsRuntimeAsyncOperation2.MakeGenericReferenceType( + operationType.TypeArguments[0], + operationMethodsType.ToReferenceTypeSignature()); + + InteropTypeDefinitionBuilder.NativeObject( + typeSignature: operationType, + nativeObjectBaseType: windowsRuntimeAsyncOperation1Type, + interopReferences: interopReferences, + module: module, + out nativeObjectType); + } + + /// + /// Creates a new type definition for the implementation of the IWindowsRuntimeUnsealedObjectComWrappersCallback interface for some IAsyncOperation1<TResult> interface. + /// + /// The for the async operation type. + /// The type returned by . + /// The 'IID' get method for . + /// The instance to use. + /// The interop module being built. + /// The resulting callback type. + public static void ComWrappersCallbackType( + TypeSignature operationType, + TypeDefinition nativeObjectType, + MethodDefinition get_IidMethod, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition callbackType) + { + ComWrappersCallback( + runtimeClassName: operationType.FullName, // TODO + typeSignature: operationType, + nativeObjectType: nativeObjectType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + out callbackType); + } + + /// + /// Creates a new type definition for the marshaller attribute of some IAsyncOperation1<TResult> interface. + /// + /// The for the async operation type. + /// The type returned by . + /// The 'IID' get method for . + /// The instance to use. + /// The module that will contain the type being created. + /// The resulting marshaller type. + public static void ComWrappersMarshallerAttribute( + GenericInstanceTypeSignature operationType, + TypeDefinition nativeObjectType, + MethodDefinition get_IidMethod, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition marshallerType) + { + InteropTypeDefinitionBuilder.ComWrappersMarshallerAttribute( + typeSignature: operationType, + nativeObjectType: nativeObjectType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + out marshallerType); + } + + /// + /// Creates a new type definition for the marshaller of some IAsyncOperation1<TResult> interface. + /// + /// The for the async operation type. + /// The instance returned by . + /// The 'IID' get method for . + /// The instance to use. + /// The module that will contain the type being created. + /// The resulting marshaller type. + public static void Marshaller( + GenericInstanceTypeSignature operationType, + TypeDefinition operationComWrappersCallbackType, + MethodDefinition get_IidMethod, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition marshallerType) + { + InteropTypeDefinitionBuilder.Marshaller( + typeSignature: operationType, + interfaceComWrappersCallbackType: operationComWrappersCallbackType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + out marshallerType); + } + + /// + /// Creates a new type definition for the interface implementation of some IAsyncOperation1<TResult> interface. + /// + /// The for the async operation type. + /// The instance returned by . + /// The instance to use. + /// The module that will contain the type being created. + /// The resulting interface implementation type. + public static void InterfaceImpl( + GenericInstanceTypeSignature operationType, + TypeDefinition operationMethodsType, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition interfaceImplType) + { + TypeSignature resultType = operationType.TypeArguments[0]; + + // We're declaring an 'internal interface class' type + interfaceImplType = new( + ns: InteropUtf8NameFactory.TypeNamespace(operationType), + name: InteropUtf8NameFactory.TypeName(operationType, "InterfaceImpl"), + attributes: TypeAttributes.Interface | TypeAttributes.AutoLayout | TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit, + baseType: null) + { + CustomAttributes = { new CustomAttribute(interopReferences.DynamicInterfaceCastableImplementationAttribute_ctor.Import(module)) }, + Interfaces = + { + new InterfaceImplementation(operationType.Import(module).ToTypeDefOrRef()), + new InterfaceImplementation(interopReferences.IAsyncInfo.Import(module)) + } + }; + + module.TopLevelTypes.Add(interfaceImplType); + + // Get the getter and setter accessor methods for 'Completed' + MethodDefinition[] completedMethods = operationMethodsType.GetMethods("Completed"u8); + + // Create the 'get_Completed' getter method + MethodDefinition get_CompletedMethod = new( + name: $"Windows.Foundation.IAsyncOperation<{resultType.FullName}>.get_Completed", + attributes: WellKnownMethodAttributesFactory.ExplicitInterfaceImplementationInstanceAccessorMethod, + signature: MethodSignature.CreateInstance(interopReferences.AsyncOperationCompletedHandler1.MakeGenericReferenceType(resultType).Import(module))); + + // Add and implement the 'get_Completed' method + interfaceImplType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperation1get_Completed(resultType).Import(module), + method: get_CompletedMethod); + + // Create a body for the 'get_Completed' method + get_CompletedMethod.CilMethodBody = WellKnownCilMethodBodyFactory.DynamicInterfaceCastableImplementation( + interfaceType: operationType, + implementationMethod: get_CompletedMethod, + forwardedMethod: completedMethods[0], + interopReferences: interopReferences, + module: module); + + // Create the 'set_Completed' getter method + MethodDefinition set_CompletedMethod = new( + name: $"Windows.Foundation.IAsyncOperation<{resultType.FullName}>.set_Completed", + attributes: WellKnownMethodAttributesFactory.ExplicitInterfaceImplementationInstanceAccessorMethod, + signature: MethodSignature.CreateInstance( + returnType: module.CorLibTypeFactory.Void, + parameterTypes: [interopReferences.AsyncOperationCompletedHandler1.MakeGenericReferenceType(resultType).Import(module)])); + + // Add and implement the 'set_Completed' method + interfaceImplType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperation1set_Completed(resultType).Import(module), + method: set_CompletedMethod); + + // Create a body for the 'set_Completed' method + set_CompletedMethod.CilMethodBody = WellKnownCilMethodBodyFactory.DynamicInterfaceCastableImplementation( + interfaceType: operationType, + implementationMethod: set_CompletedMethod, + forwardedMethod: completedMethods[1], + interopReferences: interopReferences, + module: module); + + // Create the 'Completed' property + PropertyDefinition completedProperty = new( + name: $"Windows.Foundation.IAsyncOperation<{resultType.FullName}>.Completed", + attributes: PropertyAttributes.None, + signature: PropertySignature.FromGetMethod(get_CompletedMethod)) + { + GetMethod = get_CompletedMethod, + SetMethod = set_CompletedMethod + }; + + interfaceImplType.Properties.Add(completedProperty); + + // Create the 'GetResults' method + MethodDefinition getResultsMethod = new( + name: $"Windows.Foundation.IAsyncOperation<{resultType.FullName}>.GetResults", + attributes: WellKnownMethodAttributesFactory.ExplicitInterfaceImplementationInstanceMethod, + signature: MethodSignature.CreateInstance(resultType.Import(module))); + + // Add and implement the 'GetResults' method + interfaceImplType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperation1GetResults(resultType).Import(module), + method: getResultsMethod); + + // Create a body for the 'GetResults' method + getResultsMethod.CilMethodBody = WellKnownCilMethodBodyFactory.DynamicInterfaceCastableImplementation( + interfaceType: operationType, + implementationMethod: getResultsMethod, + forwardedMethod: operationMethodsType.GetMethod("GetResults"u8), + interopReferences: interopReferences, + module: module); + } + + /// + /// Creates a new type definition for the implementation of the vtable for some IAsyncOperation1<TResult> interface. + /// + /// The for the async operation type. + /// The instance to use. + /// The instance to use. + /// The emit state for this invocation. + /// The interop module being built. + /// The resulting implementation type. + public static void ImplType( + GenericInstanceTypeSignature operationType, + InteropDefinitions interopDefinitions, + InteropReferences interopReferences, + InteropGeneratorEmitState emitState, + ModuleDefinition module, + out TypeDefinition implType) + { + TypeSignature resultType = operationType.TypeArguments[0]; + + // Prepare the 'AsyncOperationCompletedHandler<>' signature + TypeSignature asyncOperationCompletedHandlerType = interopReferences.AsyncOperationCompletedHandler1.MakeGenericReferenceType(resultType); + + // Get the generated 'ConvertToUnmanaged' method to marshal the 'AsyncOperationCompletedHandler' instance to native + MethodDefinition convertToUnmanagedMethod = emitState.LookupTypeDefinition( + typeSignature: asyncOperationCompletedHandlerType, + key: "Marshaller").GetMethod("ConvertToUnmanaged"u8); + + MethodDefinition get_CompletedMethod = InteropMethodDefinitionFactory.IAsyncInfoImpl.get_Handler( + methodName: "get_Completed"u8, + asyncInfoType: operationType, + handlerType: asyncOperationCompletedHandlerType, + get_HandlerMethod: interopReferences.IAsyncOperation1get_Completed(resultType), + convertToUnmanagedMethod: convertToUnmanagedMethod, + interopReferences: interopReferences, + module: module); + + // Get the generated 'ConvertToManaged' method to marshal the 'AsyncOperationCompletedHandler' instance to managed + MethodDefinition convertToManagedMethod = emitState.LookupTypeDefinition( + typeSignature: asyncOperationCompletedHandlerType, + key: "Marshaller").GetMethod("ConvertToManaged"u8); + + MethodDefinition set_CompletedMethod = InteropMethodDefinitionFactory.IAsyncInfoImpl.set_Handler( + methodName: "set_Completed"u8, + asyncInfoType: operationType, + handlerType: asyncOperationCompletedHandlerType, + set_HandlerMethod: interopReferences.IAsyncOperation1set_Completed(resultType), + convertToManagedMethod: convertToManagedMethod, + interopReferences: interopReferences, + module: module); + + // TODO + + Impl( + interfaceType: ComInterfaceType.InterfaceIsIInspectable, + ns: InteropUtf8NameFactory.TypeNamespace(operationType), + name: InteropUtf8NameFactory.TypeName(operationType, "Impl"), + vftblType: interopDefinitions.IAsyncOperationVftbl, + interopDefinitions: interopDefinitions, + interopReferences: interopReferences, + module: module, + implType: out implType, + vtableMethods: [ + get_CompletedMethod, + set_CompletedMethod]); + + // Track the type (it may be needed by COM interface entries for user-defined types) + emitState.TrackTypeDefinition(implType, operationType, "Impl"); + } + + /// + /// Creates a new type definition for the proxy type of some IAsyncOperation1<TResult> interface. + /// + /// The for the async operation type. + /// The instance returned by . + /// The instance to use. + /// The module that will contain the type being created. + /// The resulting proxy type. + public static void Proxy( + GenericInstanceTypeSignature operationType, + TypeDefinition operationComWrappersMarshallerAttributeType, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition proxyType) + { + string runtimeClassName = $"Windows.Foundation.IAsyncOperation`1<{operationType.TypeArguments[0]}>"; // TODO + + InteropTypeDefinitionBuilder.Proxy( + ns: InteropUtf8NameFactory.TypeNamespace(operationType), + name: InteropUtf8NameFactory.TypeName(operationType), + runtimeClassName: runtimeClassName, + comWrappersMarshallerAttributeType: operationComWrappersMarshallerAttributeType, + interopReferences: interopReferences, + module: module, + out proxyType); + } + + /// + /// Creates the type map attributes for some IAsyncOperation1<TResult> interface. + /// + /// The for the async operation type. + /// The instance returned by . + /// The instance returned by . + /// The instance to use. + /// The module that will contain the type being created. + public static void TypeMapAttributes( + GenericInstanceTypeSignature operationType, + TypeDefinition proxyType, + TypeDefinition interfaceImplType, + InteropReferences interopReferences, + ModuleDefinition module) + { + InteropTypeDefinitionBuilder.TypeMapAttributes( + runtimeClassName: $"Windows.Foundation.IAsyncOperation`1<{operationType.TypeArguments[0]}>", // TODO + externalTypeMapTargetType: proxyType.ToReferenceTypeSignature(), + externalTypeMapTrimTargetType: operationType, + proxyTypeMapSourceType: null, + proxyTypeMapProxyType: null, + interfaceTypeMapSourceType: operationType, + interfaceTypeMapProxyType: interfaceImplType.ToReferenceTypeSignature(), + interopReferences: interopReferences, + module: module); + } + } +} diff --git a/src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IAsyncOperationWithProgress2.cs b/src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IAsyncOperationWithProgress2.cs new file mode 100644 index 000000000..404cc852e --- /dev/null +++ b/src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IAsyncOperationWithProgress2.cs @@ -0,0 +1,618 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using AsmResolver.DotNet; +using AsmResolver.DotNet.Signatures; +using AsmResolver.PE.DotNet.Metadata.Tables; +using WindowsRuntime.InteropGenerator.Factories; +using WindowsRuntime.InteropGenerator.Generation; +using WindowsRuntime.InteropGenerator.References; +using static AsmResolver.PE.DotNet.Cil.CilOpCodes; + +namespace WindowsRuntime.InteropGenerator.Builders; + +/// +internal partial class InteropTypeDefinitionBuilder +{ + /// + /// Helpers for Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress> types. + /// + public static class IAsyncOperationWithProgress2 + { + /// + /// Creates the 'IID' property for some IAsyncOperationWithProgress<TResult, TProgress> interface. + /// + /// The for the async operation type. + /// The instance to use. + /// The instance to use. + /// The interop module being built. + /// The resulting 'IID' get method for . + public static void IID( + GenericInstanceTypeSignature operationType, + InteropDefinitions interopDefinitions, + InteropReferences interopReferences, + ModuleDefinition module, + out MethodDefinition get_IidMethod) + { + InteropTypeDefinitionBuilder.IID( + name: InteropUtf8NameFactory.TypeName(operationType), + interopDefinitions: interopDefinitions, + interopReferences: interopReferences, + module: module, + iid: Guid.NewGuid(), // TODO + out get_IidMethod); + } + + /// + /// Creates a new type definition for the methods for some IAsyncOperationWithProgress<TResult, TProgress> interface. + /// + /// The for the async operation type. + /// The instance to use. + /// The instance to use. + /// The emit state for this invocation. + /// The interop module being built. + /// The resulting methods type. + public static void Methods( + GenericInstanceTypeSignature operationType, + InteropDefinitions interopDefinitions, + InteropReferences interopReferences, + InteropGeneratorEmitState emitState, + ModuleDefinition module, + out TypeDefinition operationMethodsType) + { + TypeSignature resultType = operationType.TypeArguments[0]; + TypeSignature progressType = operationType.TypeArguments[1]; + + // We're declaring an 'internal static class' type + operationMethodsType = new TypeDefinition( + ns: InteropUtf8NameFactory.TypeNamespace(operationType), + name: InteropUtf8NameFactory.TypeName(operationType, "Methods"), + attributes: TypeAttributes.AutoLayout | TypeAttributes.Sealed | TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit, + baseType: module.CorLibTypeFactory.Object.ToTypeDefOrRef()) + { + Interfaces = { new InterfaceImplementation(interopReferences.IAsyncOperationWithProgressMethodsImpl2.MakeGenericReferenceType(resultType, progressType).Import(module).ToTypeDefOrRef()) } + }; + + module.TopLevelTypes.Add(operationMethodsType); + + // Prepare the handler types + TypeSignature asyncOperationProgressHandlerType = interopReferences.AsyncOperationProgressHandler2.MakeGenericReferenceType(resultType, progressType); + TypeSignature asyncOperationWithProgressCompletedHandlerType = interopReferences.AsyncOperationWithProgressCompletedHandler2.MakeGenericReferenceType(resultType, progressType); + + // Get the generated 'ConvertToManaged' method to marshal the 'AsyncOperationProgressHandler' instance to managed + MethodDefinition progressConvertToManagedMethod = emitState.LookupTypeDefinition( + typeSignature: asyncOperationProgressHandlerType, + key: "Marshaller").GetMethod("ConvertToManaged"u8); + + // Define the 'Progress' get method: + MethodDefinition get_ProgressMethod = InteropMethodDefinitionFactory.IAsyncInfoMethods.get_Handler( + methodName: "Progress"u8, + handlerType: asyncOperationProgressHandlerType, + vftblField: interopDefinitions.IAsyncOperationWithProgressVftbl.GetField("get_Progress"u8), + convertToManagedMethod: progressConvertToManagedMethod, + interopReferences: interopReferences, + module: module); + + operationMethodsType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperationWithProgressMethodsImpl2get_Progress(resultType, progressType).Import(module), + method: get_ProgressMethod); + + // Get the generated 'ConvertToUnmanaged' method to marshal the 'AsyncOperationProgressHandler' instance to native + MethodDefinition progressConvertToUnmanagedMethod = emitState.LookupTypeDefinition( + typeSignature: asyncOperationProgressHandlerType, + key: "Marshaller").GetMethod("ConvertToUnmanaged"u8); + + // Define the 'Progress' set method: + MethodDefinition set_ProgressMethod = InteropMethodDefinitionFactory.IAsyncInfoMethods.set_Handler( + methodName: "Progress"u8, + handlerType: asyncOperationProgressHandlerType, + vftblField: interopDefinitions.IAsyncOperationWithProgressVftbl.GetField("set_Progress"u8), + convertToUnmanagedMethod: progressConvertToUnmanagedMethod, + interopReferences: interopReferences, + module: module); + + operationMethodsType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperationWithProgressMethodsImpl2set_Progress(resultType, progressType).Import(module), + method: set_ProgressMethod); + + // Get the generated 'ConvertToManaged' method to marshal the 'AsyncOperationWithProgressCompletedHandler' instance to managed + MethodDefinition completedConvertToManagedMethod = emitState.LookupTypeDefinition( + typeSignature: asyncOperationWithProgressCompletedHandlerType, + key: "Marshaller").GetMethod("ConvertToManaged"u8); + + // Define the 'Completed' get method: + MethodDefinition get_CompletedMethod = InteropMethodDefinitionFactory.IAsyncInfoMethods.get_Handler( + methodName: "Completed"u8, + handlerType: asyncOperationWithProgressCompletedHandlerType, + vftblField: interopDefinitions.IAsyncOperationWithProgressVftbl.GetField("get_Completed"u8), + convertToManagedMethod: completedConvertToManagedMethod, + interopReferences: interopReferences, + module: module); + + operationMethodsType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperationWithProgressMethodsImpl2get_Completed(resultType, progressType).Import(module), + method: get_CompletedMethod); + + // Get the generated 'ConvertToUnmanaged' method to marshal the 'AsyncOperationWithProgressCompletedHandler' instance to native + MethodDefinition completedConvertToUnmanagedMethod = emitState.LookupTypeDefinition( + typeSignature: asyncOperationWithProgressCompletedHandlerType, + key: "Marshaller").GetMethod("ConvertToUnmanaged"u8); + + // Define the 'Completed' set method: + MethodDefinition set_CompletedMethod = InteropMethodDefinitionFactory.IAsyncInfoMethods.set_Handler( + methodName: "Completed"u8, + handlerType: asyncOperationWithProgressCompletedHandlerType, + vftblField: interopDefinitions.IAsyncOperationWithProgressVftbl.GetField("set_Completed"u8), + convertToUnmanagedMethod: completedConvertToUnmanagedMethod, + interopReferences: interopReferences, + module: module); + + operationMethodsType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperationWithProgressMethodsImpl2set_Completed(resultType, progressType).Import(module), + method: set_CompletedMethod); + + // Define the 'GetResults' method as follows: + // + // public static GetResults(WindowsRuntimeObjectReference thisReference) + MethodDefinition getResultsMethod = new( + name: "GetResults"u8, + attributes: MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Static, + signature: MethodSignature.CreateStatic( + returnType: resultType.Import(module), + parameterTypes: [interopReferences.WindowsRuntimeObjectReference.Import(module).ToReferenceTypeSignature()])) + { + CilInstructions = + { + { Ldnull }, + { Ret } // TODO + } + }; + + operationMethodsType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperationWithProgressMethodsImpl2GetResults(resultType, progressType).Import(module), + method: getResultsMethod); + } + + /// + /// Creates a new type definition for the native object for some IAsyncOperationWithProgress<TResult, TProgress> interface. + /// + /// The for the async operation type. + /// The instance returned by . + /// The instance to use. + /// The interop module being built. + /// The resulting native object type. + public static void NativeObject( + GenericInstanceTypeSignature operationType, + TypeDefinition operationMethodsType, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition nativeObjectType) + { + // The 'NativeObject' is deriving from 'WindowsRuntimeAsyncOperationWithProgress<, , >' + TypeSignature windowsRuntimeAsyncOperationWithProgress2Type = interopReferences.WindowsRuntimeAsyncOperationWithProgress3.MakeGenericReferenceType( + operationType.TypeArguments[0], + operationType.TypeArguments[1], + operationMethodsType.ToReferenceTypeSignature()); + + InteropTypeDefinitionBuilder.NativeObject( + typeSignature: operationType, + nativeObjectBaseType: windowsRuntimeAsyncOperationWithProgress2Type, + interopReferences: interopReferences, + module: module, + out nativeObjectType); + } + + /// + /// Creates a new type definition for the implementation of the IWindowsRuntimeUnsealedObjectComWrappersCallback interface for some IAsyncOperationWithProgress<TResult, TProgress> interface. + /// + /// The for the async operation type. + /// The type returned by . + /// The 'IID' get method for . + /// The instance to use. + /// The interop module being built. + /// The resulting callback type. + public static void ComWrappersCallbackType( + TypeSignature operationType, + TypeDefinition nativeObjectType, + MethodDefinition get_IidMethod, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition callbackType) + { + ComWrappersCallback( + runtimeClassName: operationType.FullName, // TODO + typeSignature: operationType, + nativeObjectType: nativeObjectType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + out callbackType); + } + + /// + /// Creates a new type definition for the marshaller attribute of some IAsyncOperationWithProgress<TResult, TProgress> interface. + /// + /// The for the async operation type. + /// The type returned by . + /// The 'IID' get method for . + /// The instance to use. + /// The module that will contain the type being created. + /// The resulting marshaller type. + public static void ComWrappersMarshallerAttribute( + GenericInstanceTypeSignature operationType, + TypeDefinition nativeObjectType, + MethodDefinition get_IidMethod, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition marshallerType) + { + InteropTypeDefinitionBuilder.ComWrappersMarshallerAttribute( + typeSignature: operationType, + nativeObjectType: nativeObjectType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + out marshallerType); + } + + /// + /// Creates a new type definition for the marshaller of some IAsyncOperationWithProgress<TResult, TProgress> interface. + /// + /// The for the async operation type. + /// The instance returned by . + /// The 'IID' get method for . + /// The instance to use. + /// The module that will contain the type being created. + /// The resulting marshaller type. + public static void Marshaller( + GenericInstanceTypeSignature operationType, + TypeDefinition operationComWrappersCallbackType, + MethodDefinition get_IidMethod, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition marshallerType) + { + InteropTypeDefinitionBuilder.Marshaller( + typeSignature: operationType, + interfaceComWrappersCallbackType: operationComWrappersCallbackType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + out marshallerType); + } + + /// + /// Creates a new type definition for the interface implementation of some IAsyncOperationWithProgress<TResult, TProgress> interface. + /// + /// The for the async operation type. + /// The instance returned by . + /// The instance to use. + /// The module that will contain the type being created. + /// The resulting interface implementation type. + public static void InterfaceImpl( + GenericInstanceTypeSignature operationType, + TypeDefinition operationMethodsType, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition interfaceImplType) + { + TypeSignature resultType = operationType.TypeArguments[0]; + TypeSignature progressType = operationType.TypeArguments[1]; + + // We're declaring an 'internal interface class' type + interfaceImplType = new( + ns: InteropUtf8NameFactory.TypeNamespace(operationType), + name: InteropUtf8NameFactory.TypeName(operationType, "InterfaceImpl"), + attributes: TypeAttributes.Interface | TypeAttributes.AutoLayout | TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit, + baseType: null) + { + CustomAttributes = { new CustomAttribute(interopReferences.DynamicInterfaceCastableImplementationAttribute_ctor.Import(module)) }, + Interfaces = + { + new InterfaceImplementation(operationType.Import(module).ToTypeDefOrRef()), + new InterfaceImplementation(interopReferences.IAsyncInfo.Import(module)) + } + }; + + module.TopLevelTypes.Add(interfaceImplType); + + // Prepare the handler types + TypeSignature asyncOperationProgressHandlerType = interopReferences.AsyncOperationProgressHandler2.MakeGenericReferenceType(resultType, progressType); + TypeSignature asyncOperationWithProgressCompletedHandlerType = interopReferences.AsyncOperationWithProgressCompletedHandler2.MakeGenericReferenceType(resultType, progressType); + + // Get the getter and setter accessor methods for 'Progress' + MethodDefinition[] progressMethods = operationMethodsType.GetMethods("Progress"u8); + + // Create the 'get_Progress' getter method + MethodDefinition get_ProgressMethod = new( + name: $"Windows.Foundation.IAsyncOperationWithProgress<{resultType.FullName},{progressType.FullName}>.get_Progress", + attributes: WellKnownMethodAttributesFactory.ExplicitInterfaceImplementationInstanceAccessorMethod, + signature: MethodSignature.CreateInstance(asyncOperationProgressHandlerType.Import(module))); + + // Add and implement the 'get_Progress' method + interfaceImplType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperationWithProgress2get_Progress(resultType, progressType).Import(module), + method: get_ProgressMethod); + + // Create a body for the 'get_Progress' method + get_ProgressMethod.CilMethodBody = WellKnownCilMethodBodyFactory.DynamicInterfaceCastableImplementation( + interfaceType: operationType, + implementationMethod: get_ProgressMethod, + forwardedMethod: progressMethods[0], + interopReferences: interopReferences, + module: module); + + // Create the 'set_Progress' getter method + MethodDefinition set_ProgressMethod = new( + name: $"Windows.Foundation.IAsyncOperationWithProgress<{resultType.FullName},{progressType.FullName}>.set_Progress", + attributes: WellKnownMethodAttributesFactory.ExplicitInterfaceImplementationInstanceAccessorMethod, + signature: MethodSignature.CreateInstance( + returnType: module.CorLibTypeFactory.Void, + parameterTypes: [asyncOperationProgressHandlerType.Import(module)])); + + // Add and implement the 'set_Progress' method + interfaceImplType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperationWithProgress2set_Progress(resultType, progressType).Import(module), + method: set_ProgressMethod); + + // Create a body for the 'set_Progress' method + set_ProgressMethod.CilMethodBody = WellKnownCilMethodBodyFactory.DynamicInterfaceCastableImplementation( + interfaceType: operationType, + implementationMethod: set_ProgressMethod, + forwardedMethod: progressMethods[1], + interopReferences: interopReferences, + module: module); + + // Create the 'Progress' property + PropertyDefinition progressProperty = new( + name: $"Windows.Foundation.IAsyncOperationWithProgress<{resultType.FullName},{progressType.FullName}>.Progress", + attributes: PropertyAttributes.None, + signature: PropertySignature.FromGetMethod(get_ProgressMethod)) + { + GetMethod = get_ProgressMethod, + SetMethod = set_ProgressMethod + }; + + interfaceImplType.Properties.Add(progressProperty); + + // Get the getter and setter accessor methods for 'Completed' + MethodDefinition[] completedMethods = operationMethodsType.GetMethods("Completed"u8); + + // Create the 'get_Completed' getter method + MethodDefinition get_CompletedMethod = new( + name: $"Windows.Foundation.IAsyncOperationWithProgress<{resultType.FullName},{progressType.FullName}>.get_Completed", + attributes: WellKnownMethodAttributesFactory.ExplicitInterfaceImplementationInstanceAccessorMethod, + signature: MethodSignature.CreateInstance(asyncOperationWithProgressCompletedHandlerType.Import(module))); + + // Add and implement the 'get_Completed' method + interfaceImplType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperationWithProgress2get_Completed(resultType, progressType).Import(module), + method: get_CompletedMethod); + + // Create a body for the 'get_Completed' method + get_CompletedMethod.CilMethodBody = WellKnownCilMethodBodyFactory.DynamicInterfaceCastableImplementation( + interfaceType: operationType, + implementationMethod: get_CompletedMethod, + forwardedMethod: completedMethods[0], + interopReferences: interopReferences, + module: module); + + // Create the 'set_Completed' getter method + MethodDefinition set_CompletedMethod = new( + name: $"Windows.Foundation.IAsyncOperationWithProgress<{resultType.FullName},{progressType.FullName}>.set_Completed", + attributes: WellKnownMethodAttributesFactory.ExplicitInterfaceImplementationInstanceAccessorMethod, + signature: MethodSignature.CreateInstance( + returnType: module.CorLibTypeFactory.Void, + parameterTypes: [asyncOperationWithProgressCompletedHandlerType.Import(module)])); + + // Add and implement the 'set_Completed' method + interfaceImplType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperationWithProgress2set_Completed(resultType, progressType).Import(module), + method: set_CompletedMethod); + + // Create a body for the 'set_Completed' method + set_CompletedMethod.CilMethodBody = WellKnownCilMethodBodyFactory.DynamicInterfaceCastableImplementation( + interfaceType: operationType, + implementationMethod: set_CompletedMethod, + forwardedMethod: completedMethods[1], + interopReferences: interopReferences, + module: module); + + // Create the 'Completed' property + PropertyDefinition completedProperty = new( + name: $"Windows.Foundation.IAsyncOperationWithProgress<{resultType.FullName},{progressType.FullName}>.Completed", + attributes: PropertyAttributes.None, + signature: PropertySignature.FromGetMethod(get_CompletedMethod)) + { + GetMethod = get_CompletedMethod, + SetMethod = set_CompletedMethod + }; + + interfaceImplType.Properties.Add(completedProperty); + + // Create the 'GetResults' method + MethodDefinition getResultsMethod = new( + name: $"Windows.Foundation.IAsyncOperationWithProgress<{resultType.FullName},{progressType.FullName}>.GetResults", + attributes: WellKnownMethodAttributesFactory.ExplicitInterfaceImplementationInstanceMethod, + signature: MethodSignature.CreateInstance(resultType.Import(module))); + + // Add and implement the 'GetResults' method + interfaceImplType.AddMethodImplementation( + declaration: interopReferences.IAsyncOperationWithProgress2GetResults(resultType, progressType).Import(module), + method: getResultsMethod); + + // Create a body for the 'GetResults' method + getResultsMethod.CilMethodBody = WellKnownCilMethodBodyFactory.DynamicInterfaceCastableImplementation( + interfaceType: operationType, + implementationMethod: getResultsMethod, + forwardedMethod: operationMethodsType.GetMethod("GetResults"u8), + interopReferences: interopReferences, + module: module); + } + + /// + /// Creates a new type definition for the implementation of the vtable for some IAsyncOperationWithProgress<TResult, TProgress> interface. + /// + /// The for the async operation type. + /// The instance to use. + /// The instance to use. + /// The emit state for this invocation. + /// The interop module being built. + /// The resulting implementation type. + public static void ImplType( + GenericInstanceTypeSignature operationType, + InteropDefinitions interopDefinitions, + InteropReferences interopReferences, + InteropGeneratorEmitState emitState, + ModuleDefinition module, + out TypeDefinition implType) + { + TypeSignature resultType = operationType.TypeArguments[0]; + TypeSignature progressType = operationType.TypeArguments[1]; + + // Prepare the 'AsyncOperationProgressHandler<, >' signature + TypeSignature asyncOperationProgressHandlerType = interopReferences.AsyncOperationProgressHandler2.MakeGenericReferenceType(resultType, progressType); + + // Get the generated 'ConvertToUnmanaged' method to marshal the 'AsyncOperationProgressHandler' instance to native + MethodDefinition progressConvertToUnmanagedMethod = emitState.LookupTypeDefinition( + typeSignature: asyncOperationProgressHandlerType, + key: "Marshaller").GetMethod("ConvertToUnmanaged"u8); + + MethodDefinition get_ProgressMethod = InteropMethodDefinitionFactory.IAsyncInfoImpl.get_Handler( + methodName: "get_Progress"u8, + asyncInfoType: operationType, + handlerType: asyncOperationProgressHandlerType, + get_HandlerMethod: interopReferences.IAsyncOperationWithProgress2get_Progress(resultType, progressType), + convertToUnmanagedMethod: progressConvertToUnmanagedMethod, + interopReferences: interopReferences, + module: module); + + // Get the generated 'ConvertToManaged' method to marshal the 'AsyncOperationProgressHandler' instance to managed + MethodDefinition progressConvertToManagedMethod = emitState.LookupTypeDefinition( + typeSignature: asyncOperationProgressHandlerType, + key: "Marshaller").GetMethod("ConvertToManaged"u8); + + MethodDefinition set_ProgressMethod = InteropMethodDefinitionFactory.IAsyncInfoImpl.set_Handler( + methodName: "set_Progress"u8, + asyncInfoType: operationType, + handlerType: asyncOperationProgressHandlerType, + set_HandlerMethod: interopReferences.IAsyncOperationWithProgress2set_Progress(resultType, progressType), + convertToManagedMethod: progressConvertToManagedMethod, + interopReferences: interopReferences, + module: module); + + // Prepare the 'AsyncOperationWithProgressCompletedHandler<, >' signature + TypeSignature asyncOperationWithProgressCompletedHandlerType = interopReferences.AsyncOperationWithProgressCompletedHandler2.MakeGenericReferenceType(resultType, progressType); + + // Get the generated 'ConvertToUnmanaged' method to marshal the 'AsyncOperationWithProgressCompletedHandler' instance to native + MethodDefinition completedConvertToUnmanagedMethod = emitState.LookupTypeDefinition( + typeSignature: asyncOperationWithProgressCompletedHandlerType, + key: "Marshaller").GetMethod("ConvertToUnmanaged"u8); + + MethodDefinition get_CompletedMethod = InteropMethodDefinitionFactory.IAsyncInfoImpl.get_Handler( + methodName: "get_Completed"u8, + asyncInfoType: operationType, + handlerType: asyncOperationWithProgressCompletedHandlerType, + get_HandlerMethod: interopReferences.IAsyncOperationWithProgress2get_Completed(resultType, progressType), + convertToUnmanagedMethod: completedConvertToUnmanagedMethod, + interopReferences: interopReferences, + module: module); + + // Get the generated 'ConvertToManaged' method to marshal the 'AsyncOperationWithProgressCompletedHandler' instance to managed + MethodDefinition completedConvertToManagedMethod = emitState.LookupTypeDefinition( + typeSignature: asyncOperationWithProgressCompletedHandlerType, + key: "Marshaller").GetMethod("ConvertToManaged"u8); + + MethodDefinition set_CompletedMethod = InteropMethodDefinitionFactory.IAsyncInfoImpl.set_Handler( + methodName: "set_Completed"u8, + asyncInfoType: operationType, + handlerType: asyncOperationWithProgressCompletedHandlerType, + set_HandlerMethod: interopReferences.IAsyncOperationWithProgress2set_Completed(resultType, progressType), + convertToManagedMethod: completedConvertToManagedMethod, + interopReferences: interopReferences, + module: module); + + // TODO + + Impl( + interfaceType: ComInterfaceType.InterfaceIsIInspectable, + ns: InteropUtf8NameFactory.TypeNamespace(operationType), + name: InteropUtf8NameFactory.TypeName(operationType, "Impl"), + vftblType: interopDefinitions.IAsyncOperationWithProgressVftbl, + interopDefinitions: interopDefinitions, + interopReferences: interopReferences, + module: module, + implType: out implType, + vtableMethods: [ + get_ProgressMethod, + set_ProgressMethod, + get_CompletedMethod, + set_CompletedMethod]); + + // Track the type (it may be needed by COM interface entries for user-defined types) + emitState.TrackTypeDefinition(implType, operationType, "Impl"); + } + + /// + /// Creates a new type definition for the proxy type of some IAsyncOperationWithProgress<TResult, TProgress> interface. + /// + /// The for the async operation type. + /// The instance returned by . + /// The instance to use. + /// The module that will contain the type being created. + /// The resulting proxy type. + public static void Proxy( + GenericInstanceTypeSignature operationType, + TypeDefinition operationComWrappersMarshallerAttributeType, + InteropReferences interopReferences, + ModuleDefinition module, + out TypeDefinition proxyType) + { + TypeSignature resultType = operationType.TypeArguments[0]; + TypeSignature progressType = operationType.TypeArguments[1]; + + string runtimeClassName = $"Windows.Foundation.IAsyncOperationWithProgress`2<{resultType},{progressType}>"; // TODO + + InteropTypeDefinitionBuilder.Proxy( + ns: InteropUtf8NameFactory.TypeNamespace(operationType), + name: InteropUtf8NameFactory.TypeName(operationType), + runtimeClassName: runtimeClassName, + comWrappersMarshallerAttributeType: operationComWrappersMarshallerAttributeType, + interopReferences: interopReferences, + module: module, + out proxyType); + } + + /// + /// Creates the type map attributes for some IAsyncOperationWithProgress<TResult, TProgress> interface. + /// + /// The for the async operation type. + /// The instance returned by . + /// The instance returned by . + /// The instance to use. + /// The module that will contain the type being created. + public static void TypeMapAttributes( + GenericInstanceTypeSignature operationType, + TypeDefinition proxyType, + TypeDefinition interfaceImplType, + InteropReferences interopReferences, + ModuleDefinition module) + { + TypeSignature resultType = operationType.TypeArguments[0]; + TypeSignature progressType = operationType.TypeArguments[1]; + + InteropTypeDefinitionBuilder.TypeMapAttributes( + runtimeClassName: $"Windows.Foundation.IAsyncOperationWithProgress`2<{resultType},{progressType}>", // TODO + externalTypeMapTargetType: proxyType.ToReferenceTypeSignature(), + externalTypeMapTrimTargetType: operationType, + proxyTypeMapSourceType: null, + proxyTypeMapProxyType: null, + interfaceTypeMapSourceType: operationType, + interfaceTypeMapProxyType: interfaceImplType.ToReferenceTypeSignature(), + interopReferences: interopReferences, + module: module); + } + } +} diff --git a/src/WinRT.Interop.Generator/Errors/WellKnownInteropExceptions.cs b/src/WinRT.Interop.Generator/Errors/WellKnownInteropExceptions.cs index 708007f1a..279ec1140 100644 --- a/src/WinRT.Interop.Generator/Errors/WellKnownInteropExceptions.cs +++ b/src/WinRT.Interop.Generator/Errors/WellKnownInteropExceptions.cs @@ -386,6 +386,30 @@ public static Exception DynamicImplementationDetailTypeCodeGenerationError(Excep return Exception(43, $"Failed to generate marshalling code for some dynamic implementation detail type.", exception); } + /// + /// Failed to generate marshalling code for an Windows.Foundation.IAsyncActionWithProgress<TProgress> type. + /// + public static Exception IAsyncActionWithProgressTypeCodeGenerationError(TypeSignature actionType, Exception exception) + { + return Exception(44, $"Failed to generate marshalling code for 'IAsyncActionWithProgress' type '{actionType}'.", exception); + } + + /// + /// Failed to generate marshalling code for an Windows.Foundation.IAsyncOperation<TResult> type. + /// + public static Exception IAsyncOperationTypeCodeGenerationError(TypeSignature operationType, Exception exception) + { + return Exception(45, $"Failed to generate marshalling code for 'IAsyncOperation' type '{operationType}'.", exception); + } + + /// + /// Failed to generate marshalling code for an Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress> type. + /// + public static Exception IAsyncOperationWithProgressTypeCodeGenerationError(TypeSignature operationType, Exception exception) + { + return Exception(46, $"Failed to generate marshalling code for 'IAsyncOperationWithProgress' type '{operationType}'.", exception); + } + /// /// Creates a new exception with the specified id and message. /// diff --git a/src/WinRT.Interop.Generator/Extensions/InteropGeneratorDiscoveryStateExtensions.cs b/src/WinRT.Interop.Generator/Extensions/InteropGeneratorDiscoveryStateExtensions.cs index 136ada1f1..b24f45532 100644 --- a/src/WinRT.Interop.Generator/Extensions/InteropGeneratorDiscoveryStateExtensions.cs +++ b/src/WinRT.Interop.Generator/Extensions/InteropGeneratorDiscoveryStateExtensions.cs @@ -35,7 +35,7 @@ public static void TrackGenericInterfaceType( // type. This ensures that we're never missing any 'IEnumerator' instantiation, which we might depend on // from other generated code, or projections. This special handling is needed because unlike with the other // interfaces, 'IEnumerator' will not show up as a base interface for other collection interface types. - discoveryState.TrackIEnumerator1Type(interopReferences.IEnumerator1.MakeGenericReferenceType(typeSignature.TypeArguments[0])); + discoveryState.TrackIEnumerator1Type(interopReferences.IEnumerator1.MakeGenericReferenceType([.. typeSignature.TypeArguments])); } else if (SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.IList1)) { @@ -68,12 +68,34 @@ public static void TrackGenericInterfaceType( { discoveryState.TrackIObservableMap2Type(typeSignature); - // Same handling as below for 'MapChangedEventHandler' types + // Same handling as above for 'MapChangedEventHandler' types discoveryState.TrackGenericDelegateType(interopReferences.MapChangedEventHandler2.MakeGenericReferenceType([.. typeSignature.TypeArguments])); } else if (SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.IMapChangedEventArgs1)) { discoveryState.TrackIMapChangedEventArgs1Type(typeSignature); } + else if (SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.IAsyncActionWithProgress1)) + { + discoveryState.TrackIAsyncActionWithProgress1Type(typeSignature); + + // Ensure that the delegate types for this instantiation of 'IAsyncActionWithProgress' are also tracked. + // Same rationale as above for the other special cased types. Same below as well for the other async info types. + discoveryState.TrackGenericDelegateType(interopReferences.AsyncActionProgressHandler1.MakeGenericReferenceType([.. typeSignature.TypeArguments])); + discoveryState.TrackGenericDelegateType(interopReferences.AsyncActionWithProgressCompletedHandler1.MakeGenericReferenceType([.. typeSignature.TypeArguments])); + } + else if (SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.IAsyncOperation1)) + { + discoveryState.TrackIAsyncOperation1Type(typeSignature); + + discoveryState.TrackGenericDelegateType(interopReferences.AsyncOperationCompletedHandler1.MakeGenericReferenceType([.. typeSignature.TypeArguments])); + } + else if (SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.IAsyncOperationWithProgress2)) + { + discoveryState.TrackIAsyncOperationWithProgress2Type(typeSignature); + + discoveryState.TrackGenericDelegateType(interopReferences.AsyncOperationProgressHandler2.MakeGenericReferenceType([.. typeSignature.TypeArguments])); + discoveryState.TrackGenericDelegateType(interopReferences.AsyncOperationWithProgressCompletedHandler2.MakeGenericReferenceType([.. typeSignature.TypeArguments])); + } } } diff --git a/src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IAsyncActionWithProgress1Impl.cs b/src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IAsyncActionWithProgress1Impl.cs new file mode 100644 index 000000000..2a2c0076b --- /dev/null +++ b/src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IAsyncActionWithProgress1Impl.cs @@ -0,0 +1,98 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using AsmResolver.DotNet; +using AsmResolver.DotNet.Code.Cil; +using AsmResolver.DotNet.Signatures; +using AsmResolver.PE.DotNet.Cil; +using AsmResolver.PE.DotNet.Metadata.Tables; +using WindowsRuntime.InteropGenerator.References; +using static AsmResolver.PE.DotNet.Cil.CilOpCodes; + +namespace WindowsRuntime.InteropGenerator.Factories; + +/// +internal partial class InteropMethodDefinitionFactory +{ + /// + /// Helpers for impl types for Windows.Foundation.IAsyncActionWithProgress<TProgress> interfaces. + /// + public static class IAsyncActionWithProgress1Impl + { + /// + /// Creates a for the GetResults export method. + /// + /// The for the async action type. + /// The instance to use. + /// The interop module being built. + public static MethodDefinition GetResults( + GenericInstanceTypeSignature actionType, + InteropReferences interopReferences, + ModuleDefinition module) + { + TypeSignature progressType = actionType.TypeArguments[0]; + + // Define the 'GetResults' method as follows: + // + // [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + // private static int GetResults(void* thisPtr) + MethodDefinition getResultsMethod = new( + name: "GetResults"u8, + attributes: MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static, + signature: MethodSignature.CreateStatic( + returnType: module.CorLibTypeFactory.Int32, + parameterTypes: [module.CorLibTypeFactory.Void.MakePointerType()])) + { + CustomAttributes = { InteropCustomAttributeFactory.UnmanagedCallersOnly(interopReferences, module) } + }; + + // Labels for jumps + CilInstruction ldarg_0_tryStart = new(Ldarg_0); + CilInstruction ldloc_0_returnHResult = new(Ldloc_0); + CilInstruction call_catchStartMarshalException = new(Call, interopReferences.RestrictedErrorInfoExceptionMarshallerConvertToUnmanaged.Import(module)); + + // Declare the local variables: + // [0]: 'int' (the 'HRESULT' to return) + CilLocalVariable loc_0_hresult = new(module.CorLibTypeFactory.Int32); + + // Create a method body for the 'get_Current' method + getResultsMethod.CilMethodBody = new CilMethodBody() + { + LocalVariables = { loc_0_hresult }, + Instructions = + { + // '.try' code + { ldarg_0_tryStart }, + { Call, interopReferences.ComInterfaceDispatchGetInstance.MakeGenericInstanceMethod(actionType).Import(module) }, + { Callvirt, interopReferences.IAsyncActionWithProgress1GetResults(progressType).Import(module) }, + { Ldc_I4_0 }, + { Stloc_0 }, + { Leave_S, ldloc_0_returnHResult.CreateLabel() }, + + // '.catch' code + { call_catchStartMarshalException }, + { Stloc_0 }, + { Leave_S, ldloc_0_returnHResult.CreateLabel() }, + + // Return the 'HRESULT' from location [0] + { ldloc_0_returnHResult }, + { Ret } + }, + ExceptionHandlers = + { + new CilExceptionHandler + { + HandlerType = CilExceptionHandlerType.Exception, + TryStart = ldarg_0_tryStart.CreateLabel(), + TryEnd = call_catchStartMarshalException.CreateLabel(), + HandlerStart = call_catchStartMarshalException.CreateLabel(), + HandlerEnd = ldloc_0_returnHResult.CreateLabel(), + ExceptionType = interopReferences.Exception.Import(module) + } + } + }; + + return getResultsMethod; + } + } +} diff --git a/src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IAsyncInfoImpl.cs b/src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IAsyncInfoImpl.cs new file mode 100644 index 000000000..27d009a41 --- /dev/null +++ b/src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IAsyncInfoImpl.cs @@ -0,0 +1,223 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using AsmResolver; +using AsmResolver.DotNet; +using AsmResolver.DotNet.Code.Cil; +using AsmResolver.DotNet.Signatures; +using AsmResolver.PE.DotNet.Cil; +using AsmResolver.PE.DotNet.Metadata.Tables; +using WindowsRuntime.InteropGenerator.References; +using static AsmResolver.PE.DotNet.Cil.CilOpCodes; + +#pragma warning disable IDE1006 + +namespace WindowsRuntime.InteropGenerator.Factories; + +/// +internal partial class InteropMethodDefinitionFactory +{ + /// + /// Helpers for impl types for interfaces deriving from Windows.Foundation.IAsyncInfo. + /// + public static class IAsyncInfoImpl + { + /// + /// Creates a for a get method for a handler delegate of a specified type. + /// + /// The name of the get method. + /// The type of async info interface. + /// The type of the handler delegate. + /// The interface method to invoke on . + /// The method to use to convert the handler to unmanaged. + /// The instance to use. + /// The interop module being built. + public static MethodDefinition get_Handler( + Utf8String methodName, + TypeSignature asyncInfoType, + TypeSignature handlerType, + MemberReference get_HandlerMethod, + MethodDefinition convertToUnmanagedMethod, + InteropReferences interopReferences, + ModuleDefinition module) + { + // Define the 'get_Handler' get method as follows: + // + // [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + // private static int (void* thisPtr, void** result) + MethodDefinition handlerMethod = new( + name: methodName, + attributes: MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static, + signature: MethodSignature.CreateStatic( + returnType: module.CorLibTypeFactory.Int32, + parameterTypes: [ + module.CorLibTypeFactory.Void.MakePointerType(), + module.CorLibTypeFactory.Void.MakePointerType().MakePointerType()])) + { + CustomAttributes = { InteropCustomAttributeFactory.UnmanagedCallersOnly(interopReferences, module) } + }; + + // Labels for jumps + CilInstruction nop_beforeTry = new(Nop); + CilInstruction ldarg_1_tryStart = new(Ldarg_1); + CilInstruction ldloc_0_returnHResult = new(Ldloc_0); + CilInstruction call_catchStartMarshalException = new(Call, interopReferences.RestrictedErrorInfoExceptionMarshallerConvertToUnmanaged.Import(module)); + + // Declare the local variables: + // [0]: 'int' (the 'HRESULT' to return) + // [1]: 'WindowsRuntimeObjectReferenceValue' (the marshalled async info instance) + CilLocalVariable loc_0_hresult = new(module.CorLibTypeFactory.Int32); + CilLocalVariable loc_1_handlerValue = new(interopReferences.WindowsRuntimeObjectReferenceValue.ToValueTypeSignature().Import(module)); + + // Create a method body for the 'get_Current' method + handlerMethod.CilMethodBody = new CilMethodBody() + { + LocalVariables = { loc_0_hresult, loc_1_handlerValue }, + Instructions = + { + // Return 'E_POINTER' if the argument is 'null' + { Ldarg_1 }, + { Ldc_I4_0 }, + { Conv_U }, + { Bne_Un_S, nop_beforeTry.CreateLabel() }, + { Ldc_I4, unchecked((int)0x80004003) }, + { Ret }, + { nop_beforeTry }, + + // '.try' code + { ldarg_1_tryStart }, + { Ldarg_0 }, + { Call, interopReferences.ComInterfaceDispatchGetInstance.MakeGenericInstanceMethod(asyncInfoType).Import(module) }, + { Callvirt, get_HandlerMethod.Import(module) }, + { Call, convertToUnmanagedMethod.Import(module) }, + { Stloc_1 }, + { Ldloca_S, loc_1_handlerValue }, + { Call, interopReferences.WindowsRuntimeObjectReferenceValueDetachThisPtrUnsafe.Import(module) }, + { Stind_I }, + { Ldc_I4_0 }, + { Stloc_0 }, + { Leave_S, ldloc_0_returnHResult.CreateLabel() }, + + // '.catch' code + { call_catchStartMarshalException }, + { Stloc_0 }, + { Leave_S, ldloc_0_returnHResult.CreateLabel() }, + + // Return the 'HRESULT' from location [0] + { ldloc_0_returnHResult }, + { Ret } + }, + ExceptionHandlers = + { + new CilExceptionHandler + { + HandlerType = CilExceptionHandlerType.Exception, + TryStart = ldarg_1_tryStart.CreateLabel(), + TryEnd = call_catchStartMarshalException.CreateLabel(), + HandlerStart = call_catchStartMarshalException.CreateLabel(), + HandlerEnd = ldloc_0_returnHResult.CreateLabel(), + ExceptionType = interopReferences.Exception.Import(module) + } + } + }; + + return handlerMethod; + } + + /// + /// Creates a for a set method for a handler delegate of a specified type. + /// + /// The name of the get method. + /// The type of async info interface. + /// The type of the handler delegate. + /// The interface method to invoke on . + /// The method to use to convert the handler to a managed object. + /// The instance to use. + /// The interop module being built. + public static MethodDefinition set_Handler( + Utf8String methodName, + TypeSignature asyncInfoType, + TypeSignature handlerType, + MemberReference set_HandlerMethod, + MethodDefinition convertToManagedMethod, + InteropReferences interopReferences, + ModuleDefinition module) + { + // Define the 'set_Handler' get method as follows: + // + // [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + // private static int (void* thisPtr, void* handler) + MethodDefinition handlerMethod = new( + name: methodName, + attributes: MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static, + signature: MethodSignature.CreateStatic( + returnType: module.CorLibTypeFactory.Int32, + parameterTypes: [ + module.CorLibTypeFactory.Void.MakePointerType(), + module.CorLibTypeFactory.Void.MakePointerType()])) + { + CustomAttributes = { InteropCustomAttributeFactory.UnmanagedCallersOnly(interopReferences, module) } + }; + + // Labels for jumps + CilInstruction nop_beforeTry = new(Nop); + CilInstruction ldarg_0_tryStart = new(Ldarg_0); + CilInstruction ldloc_0_returnHResult = new(Ldloc_0); + CilInstruction call_catchStartMarshalException = new(Call, interopReferences.RestrictedErrorInfoExceptionMarshallerConvertToUnmanaged.Import(module)); + + // Declare the local variables: + // [0]: 'int' (the 'HRESULT' to return) + CilLocalVariable loc_0_hresult = new(module.CorLibTypeFactory.Int32); + + // Create a method body for the 'get_Current' method + handlerMethod.CilMethodBody = new CilMethodBody() + { + LocalVariables = { loc_0_hresult }, + Instructions = + { + // Return 'E_POINTER' if the argument is 'null' + { Ldarg_1 }, + { Ldc_I4_0 }, + { Conv_U }, + { Bne_Un_S, nop_beforeTry.CreateLabel() }, + { Ldc_I4, unchecked((int)0x80004003) }, + { Ret }, + { nop_beforeTry }, + + // '.try' code + { ldarg_0_tryStart }, + { Call, interopReferences.ComInterfaceDispatchGetInstance.MakeGenericInstanceMethod(asyncInfoType).Import(module) }, + { Ldarg_1 }, + { Call, convertToManagedMethod.Import(module) }, + { Callvirt, set_HandlerMethod.Import(module) }, + { Ldc_I4_0 }, + { Stloc_0 }, + { Leave_S, ldloc_0_returnHResult.CreateLabel() }, + + // '.catch' code + { call_catchStartMarshalException }, + { Stloc_0 }, + { Leave_S, ldloc_0_returnHResult.CreateLabel() }, + + // Return the 'HRESULT' from location [0] + { ldloc_0_returnHResult }, + { Ret } + }, + ExceptionHandlers = + { + new CilExceptionHandler + { + HandlerType = CilExceptionHandlerType.Exception, + TryStart = ldarg_0_tryStart.CreateLabel(), + TryEnd = call_catchStartMarshalException.CreateLabel(), + HandlerStart = call_catchStartMarshalException.CreateLabel(), + HandlerEnd = ldloc_0_returnHResult.CreateLabel(), + ExceptionType = interopReferences.Exception.Import(module) + } + } + }; + + return handlerMethod; + } + } +} diff --git a/src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IAsyncInfoMethods.cs b/src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IAsyncInfoMethods.cs new file mode 100644 index 000000000..447f867d2 --- /dev/null +++ b/src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IAsyncInfoMethods.cs @@ -0,0 +1,286 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using AsmResolver; +using AsmResolver.DotNet; +using AsmResolver.DotNet.Code.Cil; +using AsmResolver.DotNet.Signatures; +using AsmResolver.PE.DotNet.Cil; +using AsmResolver.PE.DotNet.Metadata.Tables; +using WindowsRuntime.InteropGenerator.References; +using static AsmResolver.PE.DotNet.Cil.CilOpCodes; + +#pragma warning disable IDE1006 + +namespace WindowsRuntime.InteropGenerator.Factories; + +/// +internal partial class InteropMethodDefinitionFactory +{ + /// + /// Helpers for method types for interfaces deriving from Windows.Foundation.IAsyncInfo. + /// + public static class IAsyncInfoMethods + { + /// + /// Creates a for a get method for a handler delegate of a specified type. + /// + /// The name of the get method. + /// The type of the handler delegate. + /// The vtable field definition for the interface slot to invoke. + /// The marshalling method to convert the handler delegate native pointer. + /// The instance to use. + /// The interop module being built. + public static MethodDefinition get_Handler( + Utf8String methodName, + TypeSignature handlerType, + FieldDefinition vftblField, + MethodDefinition convertToManagedMethod, + InteropReferences interopReferences, + ModuleDefinition module) + { + // Define the 'Handler' get method as follows: + // + // public static (WindowsRuntimeObjectReference thisReference) + MethodDefinition handlerMethod = new( + name: methodName, + attributes: MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Static, + signature: MethodSignature.CreateStatic( + returnType: handlerType.Import(module), + parameterTypes: [interopReferences.WindowsRuntimeObjectReference.Import(module).ToReferenceTypeSignature()])) + { NoInlining = true }; + + // Declare the local variables: + // [0]: 'WindowsRuntimeObjectReferenceValue' (for 'thisValue') + // [1]: 'void*' (for 'thisPtr') + // [2]: 'void*' (the handler pointer that was retrieved) + // [3]: '' (the marshalled handler) + CilLocalVariable loc_0_thisValue = new(interopReferences.WindowsRuntimeObjectReferenceValue.ToValueTypeSignature().Import(module)); + CilLocalVariable loc_1_thisPtr = new(module.CorLibTypeFactory.Void.MakePointerType()); + CilLocalVariable loc_2_handlerPtr = new(module.CorLibTypeFactory.Void.MakePointerType()); + CilLocalVariable loc_3_handler = new(handlerType.Import(module)); + + // Jump labels + CilInstruction ldloca_s_0_tryStart = new(Ldloca_S, loc_0_thisValue); + CilInstruction ldloca_s_0_finallyStart = new(Ldloca_S, loc_0_thisValue); + CilInstruction nop_finallyEnd = new(Nop); + CilInstruction ldloc_2_tryStart = new(Ldloc_2); + CilInstruction ldloc_2_finallyStart = new(Ldloc_2); + CilInstruction ldloc_3_finallyEnd = new(Ldloc_3); + + // Create a method body for the 'Handler' method + handlerMethod.CilMethodBody = new CilMethodBody() + { + LocalVariables = { loc_0_thisValue, loc_1_thisPtr, loc_2_handlerPtr, loc_3_handler }, + Instructions = + { + // Initialize 'thisValue' + { Ldarg_0 }, + { Callvirt, interopReferences.WindowsRuntimeObjectReferenceAsValue.Import(module) }, + { Stloc_0 }, + + // '.try' code + { ldloca_s_0_tryStart }, + { Call, interopReferences.WindowsRuntimeObjectReferenceValueGetThisPtrUnsafe.Import(module) }, + { Stloc_1 }, + { Ldloc_1 }, + { Ldloca_S, loc_2_handlerPtr }, + { Ldloc_1 }, + { Ldind_I }, + { Ldfld, vftblField }, + { Calli, WellKnownTypeSignatureFactory.get_Handler(interopReferences).Import(module).MakeStandAloneSignature() }, + { Call, interopReferences.RestrictedErrorInfoThrowExceptionForHR.Import(module) }, + { Leave_S, nop_finallyEnd.CreateLabel() }, + + // '.finally' code + { ldloca_s_0_finallyStart }, + { Call, interopReferences.WindowsRuntimeObjectReferenceValueDispose.Import(module) }, + { Endfinally }, + { nop_finallyEnd }, + + // '.try/.finally' code to marshal the handler + { ldloc_2_tryStart }, + { Call, convertToManagedMethod }, + { Stloc_3 }, + { Leave_S, ldloc_3_finallyEnd.CreateLabel() }, + { ldloc_2_finallyStart }, + { Call, interopReferences.WindowsRuntimeObjectMarshallerFree.Import(module) }, + { Endfinally }, + { ldloc_3_finallyEnd }, + { Ret } + }, + ExceptionHandlers = + { + new CilExceptionHandler + { + HandlerType = CilExceptionHandlerType.Finally, + TryStart = ldloca_s_0_tryStart.CreateLabel(), + TryEnd = ldloca_s_0_finallyStart.CreateLabel(), + HandlerStart = ldloca_s_0_finallyStart.CreateLabel(), + HandlerEnd = nop_finallyEnd.CreateLabel() + }, + new CilExceptionHandler + { + HandlerType = CilExceptionHandlerType.Finally, + TryStart = ldloc_2_tryStart.CreateLabel(), + TryEnd = ldloc_2_finallyStart.CreateLabel(), + HandlerStart = ldloc_2_finallyStart.CreateLabel(), + HandlerEnd = ldloc_3_finallyEnd.CreateLabel() + } + } + }; + + return handlerMethod; + } + + /// + /// Creates a for a set method for a handler delegate of a specified type. + /// + /// The name of the set method. + /// The type of the handler delegate. + /// The vtable field definition for the interface slot to invoke. + /// The marshalling method to convert the handler delegate managed object. + /// The instance to use. + /// The interop module being built. + public static MethodDefinition set_Handler( + Utf8String methodName, + TypeSignature handlerType, + FieldDefinition vftblField, + MethodDefinition convertToUnmanagedMethod, + InteropReferences interopReferences, + ModuleDefinition module) + { + // Define the 'Handler' set method as follows: + // + // public static void (WindowsRuntimeObjectReference thisReference, handler) + MethodDefinition handlerMethod = new( + name: methodName, + attributes: MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Static, + signature: MethodSignature.CreateStatic( + returnType: module.CorLibTypeFactory.Void, + parameterTypes: [ + interopReferences.WindowsRuntimeObjectReference.Import(module).ToReferenceTypeSignature(), + handlerType.Import(module)])) + { NoInlining = true }; + + // Declare the local variables: + // [0]: 'WindowsRuntimeObjectReferenceValue' (for 'thisValue') + // [1]: 'WindowsRuntimeObjectReferenceValue' (for 'handlerValue') + // [2]: 'void*' (for 'thisPtr') + CilLocalVariable loc_0_thisValue = new(interopReferences.WindowsRuntimeObjectReferenceValue.ToValueTypeSignature().Import(module)); + CilLocalVariable loc_1_handlerValue = new(interopReferences.WindowsRuntimeObjectReferenceValue.ToValueTypeSignature().Import(module)); + CilLocalVariable loc_2_thisPtr = new(module.CorLibTypeFactory.Void.MakePointerType()); + + // Jump labels + CilInstruction ldarg_1_tryStart = new(Ldarg_1); + CilInstruction ldloca_s_0_tryStart = new(Ldloca_S, loc_0_thisValue); + CilInstruction ldloca_s_1_finallyStart = new(Ldloca_S, loc_1_handlerValue); + CilInstruction ldloca_s_0_finallyStart = new(Ldloca_S, loc_0_thisValue); + CilInstruction ret_finallyEnd = new(Ret); + + // Create a method body for the 'Handler' method + handlerMethod.CilMethodBody = new CilMethodBody() + { + LocalVariables = { loc_0_thisValue, loc_1_handlerValue, loc_2_thisPtr }, + Instructions = + { + // Initialize 'thisValue' + { Ldarg_0 }, + { Callvirt, interopReferences.WindowsRuntimeObjectReferenceAsValue.Import(module) }, + { Stloc_0 }, + + // Initialize 'handlerValue' + { ldarg_1_tryStart }, + { Call, convertToUnmanagedMethod }, + { Stloc_1 }, + + // '.try' code + { ldloca_s_0_tryStart }, + { Call, interopReferences.WindowsRuntimeObjectReferenceValueGetThisPtrUnsafe.Import(module) }, + { Stloc_2 }, + { Ldloc_2 }, + { Ldloca_S, loc_1_handlerValue }, + { Call, interopReferences.WindowsRuntimeObjectReferenceValueGetThisPtrUnsafe.Import(module) }, + { Ldloc_2 }, + { Ldind_I }, + { Ldfld, vftblField }, + { Calli, WellKnownTypeSignatureFactory.set_Handler(interopReferences).Import(module).MakeStandAloneSignature() }, + { Call, interopReferences.RestrictedErrorInfoThrowExceptionForHR.Import(module) }, + { Leave_S, ret_finallyEnd.CreateLabel() }, + + // '.finally' code (for 'handlerValue') + { ldloca_s_1_finallyStart }, + { Call, interopReferences.WindowsRuntimeObjectReferenceValueDispose.Import(module) }, + { Endfinally }, + + // '.finally' code (for 'thisValue') + { ldloca_s_0_finallyStart }, + { Call, interopReferences.WindowsRuntimeObjectReferenceValueDispose.Import(module) }, + { Endfinally }, + + // Return (after both '.finally' blocks) + { ret_finallyEnd } + }, + ExceptionHandlers = + { + new CilExceptionHandler + { + HandlerType = CilExceptionHandlerType.Finally, + TryStart = ldarg_1_tryStart.CreateLabel(), + TryEnd = ldloca_s_0_finallyStart.CreateLabel(), + HandlerStart = ldloca_s_0_finallyStart.CreateLabel(), + HandlerEnd = ret_finallyEnd.CreateLabel() + }, + new CilExceptionHandler + { + HandlerType = CilExceptionHandlerType.Finally, + TryStart = ldloca_s_0_tryStart.CreateLabel(), + TryEnd = ldloca_s_1_finallyStart.CreateLabel(), + HandlerStart = ldloca_s_1_finallyStart.CreateLabel(), + HandlerEnd = ldloca_s_0_finallyStart.CreateLabel() + } + } + }; + + return handlerMethod; + } + +#pragma warning disable CS1573, IDE0017 // TODO + + /// + /// Creates a for the GetResults method of some async operation type. + /// + /// The vtable field definition for the interface slot to invoke. + /// The instance to use. + /// The interop module being built. + public static MethodDefinition GetResults( + TypeSignature resultType, + FieldDefinition vftblField, + InteropReferences interopReferences, + ModuleDefinition module) + { + // Define the 'GetResults' get method as follows: + // + // public static GetResults(WindowsRuntimeObjectReference thisReference) + MethodDefinition getResultsMethod = new( + name: "GetResults"u8, + attributes: MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Static, + signature: MethodSignature.CreateStatic( + returnType: resultType.Import(module), + parameterTypes: [interopReferences.WindowsRuntimeObjectReference.Import(module).ToReferenceTypeSignature()])) + { NoInlining = true }; + + // Create a method body for the 'GetResults' method + getResultsMethod.CilMethodBody = new CilMethodBody() + { + Instructions = + { + { Ldnull }, // TODO + { Throw } + }, + }; + + return getResultsMethod; + } + } +} diff --git a/src/WinRT.Interop.Generator/Factories/WellKnownTypeDefinitionFactory.cs b/src/WinRT.Interop.Generator/Factories/WellKnownTypeDefinitionFactory.cs index 7de1c0462..5f90d6a9b 100644 --- a/src/WinRT.Interop.Generator/Factories/WellKnownTypeDefinitionFactory.cs +++ b/src/WinRT.Interop.Generator/Factories/WellKnownTypeDefinitionFactory.cs @@ -119,7 +119,7 @@ public static TypeDefinition DelegateVftbl(InteropReferences interopReferences, // public delegate* unmanaged[MemberFunction] QueryInterface; // public delegate* unmanaged[MemberFunction] AddRef; // public delegate* unmanaged[MemberFunction] Release; - // public delegate* unmanaged[MemberFunction] Invoke; + // public delegate* unmanaged[MemberFunction] Invoke; vftblType.Fields.Add(new FieldDefinition("QueryInterface"u8, FieldAttributes.Public, queryInterfaceType.Import(module).MakeFunctionPointerType())); vftblType.Fields.Add(new FieldDefinition("AddRef"u8, FieldAttributes.Public, addRefType.Import(module).MakeFunctionPointerType())); vftblType.Fields.Add(new FieldDefinition("Release"u8, FieldAttributes.Public, releaseType.Import(module).MakeFunctionPointerType())); @@ -152,7 +152,7 @@ public static TypeDefinition DelegateReferenceVftbl(InteropReferences interopRef MethodSignature getRuntimeClassNameType = WellKnownTypeSignatureFactory.GetRuntimeClassNameImpl(interopReferences); MethodSignature getTrustLevelType = WellKnownTypeSignatureFactory.GetTrustLevelImpl(interopReferences); - // Signature for 'delegate* unmanaged[MemberFunction]' + // Signature for 'delegate* unmanaged[MemberFunction]' MethodSignature valueType = new( attributes: CallingConventionAttributes.Unmanaged, returnType: new CustomModifierTypeSignature( @@ -727,7 +727,7 @@ public static TypeDefinition IKeyValuePairVftbl(InteropReferences interopReferen MethodSignature getRuntimeClassNameType = WellKnownTypeSignatureFactory.GetRuntimeClassNameImpl(interopReferences); MethodSignature getTrustLevelType = WellKnownTypeSignatureFactory.GetTrustLevelImpl(interopReferences); - // Signature for 'delegate* unmanaged[MemberFunction]' + // Signature for 'delegate* unmanaged[MemberFunction]' MethodSignature get_KeyOrValueType = new( attributes: CallingConventionAttributes.Unmanaged, returnType: new CustomModifierTypeSignature( @@ -821,7 +821,7 @@ public static TypeDefinition IMapChangedEventArgsVftbl(InteropReferences interop MethodSignature getRuntimeClassNameType = WellKnownTypeSignatureFactory.GetRuntimeClassNameImpl(interopReferences); MethodSignature getTrustLevelType = WellKnownTypeSignatureFactory.GetTrustLevelImpl(interopReferences); - // Signature for 'delegate* unmanaged[MemberFunction]' + // Signature for 'delegate* unmanaged[MemberFunction]' MethodSignature collectionChangeType = new( attributes: CallingConventionAttributes.Unmanaged, returnType: new CustomModifierTypeSignature( @@ -832,7 +832,7 @@ public static TypeDefinition IMapChangedEventArgsVftbl(InteropReferences interop module.CorLibTypeFactory.Void.MakePointerType(), interopReferences.CollectionChange.MakePointerType()]); - // Signature for 'delegate* unmanaged[MemberFunction]' + // Signature for 'delegate* unmanaged[MemberFunction]' MethodSignature keyType = new( attributes: CallingConventionAttributes.Unmanaged, returnType: new CustomModifierTypeSignature( @@ -901,8 +901,8 @@ public static TypeDefinition IObservableVectorVftbl(InteropReferences interopRef // public delegate* unmanaged[MemberFunction] GetIids; // public delegate* unmanaged[MemberFunction] GetRuntimeClassName; // public delegate* unmanaged[MemberFunction] GetTrustLevel; - // public delegate* unmanaged[MemberFunction] add_VectorChanged; - // public delegate* unmanaged[MemberFunction] remove_VectorChanged; + // public delegate* unmanaged[MemberFunction] add_VectorChanged; + // public delegate* unmanaged[MemberFunction] remove_VectorChanged; vftblType.Fields.Add(new FieldDefinition("QueryInterface"u8, FieldAttributes.Public, queryInterfaceType.Import(module).MakeFunctionPointerType())); vftblType.Fields.Add(new FieldDefinition("AddRef"u8, FieldAttributes.Public, addRefType.Import(module).MakeFunctionPointerType())); vftblType.Fields.Add(new FieldDefinition("Release"u8, FieldAttributes.Public, releaseType.Import(module).MakeFunctionPointerType())); @@ -951,8 +951,8 @@ public static TypeDefinition IObservableMapVftbl(InteropReferences interopRefere // public delegate* unmanaged[MemberFunction] GetIids; // public delegate* unmanaged[MemberFunction] GetRuntimeClassName; // public delegate* unmanaged[MemberFunction] GetTrustLevel; - // public delegate* unmanaged[MemberFunction] add_MapChanged; - // public delegate* unmanaged[MemberFunction] remove_MapChanged; + // public delegate* unmanaged[MemberFunction] add_MapChanged; + // public delegate* unmanaged[MemberFunction] remove_MapChanged; vftblType.Fields.Add(new FieldDefinition("QueryInterface"u8, FieldAttributes.Public, queryInterfaceType.Import(module).MakeFunctionPointerType())); vftblType.Fields.Add(new FieldDefinition("AddRef"u8, FieldAttributes.Public, addRefType.Import(module).MakeFunctionPointerType())); vftblType.Fields.Add(new FieldDefinition("Release"u8, FieldAttributes.Public, releaseType.Import(module).MakeFunctionPointerType())); @@ -965,6 +965,193 @@ public static TypeDefinition IObservableMapVftbl(InteropReferences interopRefere return vftblType; } + /// + /// Creates a new type definition for the vtable of an 'IAsyncActionWithProgress`1<TProgress>' instantiation for some type. + /// + /// The instance to use. + /// The module that will contain the type being created. + /// The resulting instance. + public static TypeDefinition IAsyncActionWithProgressVftbl(InteropReferences interopReferences, ModuleDefinition module) + { + TypeDefinition vftblType = new( + ns: null, + name: ""u8, + attributes: TypeAttributes.SequentialLayout | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit, + baseType: interopReferences.ValueType.Import(module)); + + // Get the 'IUnknown' signatures + MethodSignature queryInterfaceType = WellKnownTypeSignatureFactory.QueryInterfaceImpl(interopReferences); + MethodSignature addRefType = WellKnownTypeSignatureFactory.AddRefImpl(interopReferences); + MethodSignature releaseType = WellKnownTypeSignatureFactory.ReleaseImpl(interopReferences); + + // Get the 'IInspectable' signatures + MethodSignature getIidsType = WellKnownTypeSignatureFactory.GetIidsImpl(interopReferences); + MethodSignature getRuntimeClassNameType = WellKnownTypeSignatureFactory.GetRuntimeClassNameImpl(interopReferences); + MethodSignature getTrustLevelType = WellKnownTypeSignatureFactory.GetTrustLevelImpl(interopReferences); + + // Get the 'Progress' signatures + MethodSignature get_ProgressType = WellKnownTypeSignatureFactory.get_Handler(interopReferences); + MethodSignature set_ProgressType = WellKnownTypeSignatureFactory.set_Handler(interopReferences); + + // Get the 'Completed' signatures + MethodSignature get_CompletedType = WellKnownTypeSignatureFactory.get_Handler(interopReferences); + MethodSignature set_CompletedType = WellKnownTypeSignatureFactory.set_Handler(interopReferences); + + // Signature for 'delegate* unmanaged[MemberFunction]' + MethodSignature getResultsType = new( + attributes: CallingConventionAttributes.Unmanaged, + returnType: new CustomModifierTypeSignature( + modifierType: interopReferences.CallConvMemberFunction, + isRequired: false, + baseType: interopReferences.CorLibTypeFactory.Int32), + parameterTypes: [interopReferences.CorLibTypeFactory.Void.MakePointerType()]); + + // The vtable layout for 'IAsyncActionWithProgress`1' looks like this: + // + // public delegate* unmanaged[MemberFunction] QueryInterface; + // public delegate* unmanaged[MemberFunction] AddRef; + // public delegate* unmanaged[MemberFunction] Release; + // public delegate* unmanaged[MemberFunction] GetIids; + // public delegate* unmanaged[MemberFunction] GetRuntimeClassName; + // public delegate* unmanaged[MemberFunction] GetTrustLevel; + // public delegate* unmanaged[MemberFunction] get_Progress; + // public delegate* unmanaged[MemberFunction] set_Progress; + // public delegate* unmanaged[MemberFunction] get_Completed; + // public delegate* unmanaged[MemberFunction] set_Completed; + // public delegate* unmanaged[MemberFunction] GetResults; + vftblType.Fields.Add(new FieldDefinition("QueryInterface"u8, FieldAttributes.Public, queryInterfaceType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("AddRef"u8, FieldAttributes.Public, addRefType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("Release"u8, FieldAttributes.Public, releaseType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("GetIids"u8, FieldAttributes.Public, getIidsType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("GetRuntimeClassName"u8, FieldAttributes.Public, getRuntimeClassNameType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("GetTrustLevel"u8, FieldAttributes.Public, getTrustLevelType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("get_Progress"u8, FieldAttributes.Public, get_ProgressType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("set_Progress"u8, FieldAttributes.Public, set_ProgressType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("get_Completed"u8, FieldAttributes.Public, get_CompletedType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("set_Completed"u8, FieldAttributes.Public, set_CompletedType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("GetResults"u8, FieldAttributes.Public, getResultsType.Import(module).MakeFunctionPointerType())); + + return vftblType; + } + + /// + /// Creates a new type definition for the vtable of an 'IAsyncOperation`1<TResult>' instantiation for some type. + /// + /// The instance to use. + /// The module that will contain the type being created. + /// The resulting instance. + public static TypeDefinition IAsyncOperationVftbl(InteropReferences interopReferences, ModuleDefinition module) + { + TypeDefinition vftblType = new( + ns: null, + name: ""u8, + attributes: TypeAttributes.SequentialLayout | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit, + baseType: interopReferences.ValueType.Import(module)); + + // Get the 'IUnknown' signatures + MethodSignature queryInterfaceType = WellKnownTypeSignatureFactory.QueryInterfaceImpl(interopReferences); + MethodSignature addRefType = WellKnownTypeSignatureFactory.AddRefImpl(interopReferences); + MethodSignature releaseType = WellKnownTypeSignatureFactory.ReleaseImpl(interopReferences); + + // Get the 'IInspectable' signatures + MethodSignature getIidsType = WellKnownTypeSignatureFactory.GetIidsImpl(interopReferences); + MethodSignature getRuntimeClassNameType = WellKnownTypeSignatureFactory.GetRuntimeClassNameImpl(interopReferences); + MethodSignature getTrustLevelType = WellKnownTypeSignatureFactory.GetTrustLevelImpl(interopReferences); + + // Get the 'Completed' signatures + MethodSignature get_CompletedType = WellKnownTypeSignatureFactory.get_Handler(interopReferences); + MethodSignature set_CompletedType = WellKnownTypeSignatureFactory.set_Handler(interopReferences); + + // Get the 'GetResults' signature + MethodSignature getResultsType = WellKnownTypeSignatureFactory.get_UntypedRetVal(interopReferences); + + // The vtable layout for 'IAsyncOperation`1' looks like this: + // + // public delegate* unmanaged[MemberFunction] QueryInterface; + // public delegate* unmanaged[MemberFunction] AddRef; + // public delegate* unmanaged[MemberFunction] Release; + // public delegate* unmanaged[MemberFunction] GetIids; + // public delegate* unmanaged[MemberFunction] GetRuntimeClassName; + // public delegate* unmanaged[MemberFunction] GetTrustLevel; + // public delegate* unmanaged[MemberFunction] get_Completed; + // public delegate* unmanaged[MemberFunction] set_Completed; + // public delegate* unmanaged[MemberFunction] GetResults; + vftblType.Fields.Add(new FieldDefinition("QueryInterface"u8, FieldAttributes.Public, queryInterfaceType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("AddRef"u8, FieldAttributes.Public, addRefType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("Release"u8, FieldAttributes.Public, releaseType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("GetIids"u8, FieldAttributes.Public, getIidsType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("GetRuntimeClassName"u8, FieldAttributes.Public, getRuntimeClassNameType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("GetTrustLevel"u8, FieldAttributes.Public, getTrustLevelType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("get_Completed"u8, FieldAttributes.Public, get_CompletedType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("set_Completed"u8, FieldAttributes.Public, set_CompletedType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("GetResults"u8, FieldAttributes.Public, getResultsType.Import(module).MakeFunctionPointerType())); + + return vftblType; + } + + /// + /// Creates a new type definition for the vtable of an 'IAsyncOperationWithProgress`2<TResult, TProgress>' instantiation for some type. + /// + /// The instance to use. + /// The module that will contain the type being created. + /// The resulting instance. + public static TypeDefinition IAsyncOperationWithProgressVftbl(InteropReferences interopReferences, ModuleDefinition module) + { + TypeDefinition vftblType = new( + ns: null, + name: ""u8, + attributes: TypeAttributes.SequentialLayout | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit, + baseType: interopReferences.ValueType.Import(module)); + + // Get the 'IUnknown' signatures + MethodSignature queryInterfaceType = WellKnownTypeSignatureFactory.QueryInterfaceImpl(interopReferences); + MethodSignature addRefType = WellKnownTypeSignatureFactory.AddRefImpl(interopReferences); + MethodSignature releaseType = WellKnownTypeSignatureFactory.ReleaseImpl(interopReferences); + + // Get the 'IInspectable' signatures + MethodSignature getIidsType = WellKnownTypeSignatureFactory.GetIidsImpl(interopReferences); + MethodSignature getRuntimeClassNameType = WellKnownTypeSignatureFactory.GetRuntimeClassNameImpl(interopReferences); + MethodSignature getTrustLevelType = WellKnownTypeSignatureFactory.GetTrustLevelImpl(interopReferences); + + // Get the 'Progress' signatures + MethodSignature get_ProgressType = WellKnownTypeSignatureFactory.get_Handler(interopReferences); + MethodSignature set_ProgressType = WellKnownTypeSignatureFactory.set_Handler(interopReferences); + + // Get the 'Completed' signatures + MethodSignature get_CompletedType = WellKnownTypeSignatureFactory.get_Handler(interopReferences); + MethodSignature set_CompletedType = WellKnownTypeSignatureFactory.set_Handler(interopReferences); + + // Get the 'GetResults' signature + MethodSignature getResultsType = WellKnownTypeSignatureFactory.get_UntypedRetVal(interopReferences); + + // The vtable layout for 'IAsyncOperation`1' looks like this: + // + // public delegate* unmanaged[MemberFunction] QueryInterface; + // public delegate* unmanaged[MemberFunction] AddRef; + // public delegate* unmanaged[MemberFunction] Release; + // public delegate* unmanaged[MemberFunction] GetIids; + // public delegate* unmanaged[MemberFunction] GetRuntimeClassName; + // public delegate* unmanaged[MemberFunction] GetTrustLevel; + // public delegate* unmanaged[MemberFunction] get_Progress; + // public delegate* unmanaged[MemberFunction] set_Progress; + // public delegate* unmanaged[MemberFunction] get_Completed; + // public delegate* unmanaged[MemberFunction] set_Completed; + // public delegate* unmanaged[MemberFunction] GetResults; + vftblType.Fields.Add(new FieldDefinition("QueryInterface"u8, FieldAttributes.Public, queryInterfaceType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("AddRef"u8, FieldAttributes.Public, addRefType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("Release"u8, FieldAttributes.Public, releaseType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("GetIids"u8, FieldAttributes.Public, getIidsType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("GetRuntimeClassName"u8, FieldAttributes.Public, getRuntimeClassNameType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("GetTrustLevel"u8, FieldAttributes.Public, getTrustLevelType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("get_Progress"u8, FieldAttributes.Public, get_ProgressType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("set_Progress"u8, FieldAttributes.Public, set_ProgressType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("get_Completed"u8, FieldAttributes.Public, get_CompletedType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("set_Completed"u8, FieldAttributes.Public, set_CompletedType.Import(module).MakeFunctionPointerType())); + vftblType.Fields.Add(new FieldDefinition("GetResults"u8, FieldAttributes.Public, getResultsType.Import(module).MakeFunctionPointerType())); + + return vftblType; + } + /// /// Creates a new type definition for the vtable of an 'IReferenceArray`1<T>' instantiation for some SZ array type. /// @@ -989,7 +1176,7 @@ public static TypeDefinition ReferenceArrayVftbl(InteropReferences interopRefere MethodSignature getRuntimeClassNameType = WellKnownTypeSignatureFactory.GetRuntimeClassNameImpl(interopReferences); MethodSignature getTrustLevelType = WellKnownTypeSignatureFactory.GetTrustLevelImpl(interopReferences); - // Signature for 'delegate* unmanaged[MemberFunction]' + // Signature for 'delegate* unmanaged[MemberFunction]' MethodSignature valueType = new( attributes: CallingConventionAttributes.Unmanaged, returnType: new CustomModifierTypeSignature( diff --git a/src/WinRT.Interop.Generator/Factories/WellKnownTypeSignatureFactory.cs b/src/WinRT.Interop.Generator/Factories/WellKnownTypeSignatureFactory.cs index defa180c6..9758a45f8 100644 --- a/src/WinRT.Interop.Generator/Factories/WellKnownTypeSignatureFactory.cs +++ b/src/WinRT.Interop.Generator/Factories/WellKnownTypeSignatureFactory.cs @@ -75,7 +75,7 @@ public static MethodSignature ReleaseImpl(InteropReferences interopReferences) /// The resulting instance. public static MethodSignature GetIidsImpl(InteropReferences interopReferences) { - // Signature for 'delegate* unmanaged[MemberFunction]' + // Signature for 'delegate* unmanaged[MemberFunction]' return new( attributes: CallingConventionAttributes.Unmanaged, returnType: new CustomModifierTypeSignature( @@ -95,7 +95,7 @@ public static MethodSignature GetIidsImpl(InteropReferences interopReferences) /// The resulting instance. public static MethodSignature GetRuntimeClassNameImpl(InteropReferences interopReferences) { - // Signature for 'delegate* unmanaged[MemberFunction]' + // Signature for 'delegate* unmanaged[MemberFunction]' return new( attributes: CallingConventionAttributes.Unmanaged, returnType: new CustomModifierTypeSignature( @@ -114,7 +114,7 @@ public static MethodSignature GetRuntimeClassNameImpl(InteropReferences interopR /// The resulting instance. public static MethodSignature GetTrustLevelImpl(InteropReferences interopReferences) { - // Signature for 'delegate* unmanaged[MemberFunction]' + // Signature for 'delegate* unmanaged[MemberFunction]' return new( attributes: CallingConventionAttributes.Unmanaged, returnType: new CustomModifierTypeSignature( @@ -133,7 +133,7 @@ public static MethodSignature GetTrustLevelImpl(InteropReferences interopReferen /// The resulting instance. public static MethodSignature add_EventHandler(InteropReferences interopReferences) { - // Signature for 'delegate* unmanaged[MemberFunction]' + // Signature for 'delegate* unmanaged[MemberFunction]' return new( attributes: CallingConventionAttributes.Unmanaged, returnType: new CustomModifierTypeSignature( @@ -153,7 +153,7 @@ public static MethodSignature add_EventHandler(InteropReferences interopReferenc /// The resulting instance. public static MethodSignature remove_EventHandler(InteropReferences interopReferences) { - // Signature for 'delegate* unmanaged[MemberFunction]' + // Signature for 'delegate* unmanaged[MemberFunction]' return new( attributes: CallingConventionAttributes.Unmanaged, returnType: new CustomModifierTypeSignature( @@ -165,6 +165,63 @@ public static MethodSignature remove_EventHandler(InteropReferences interopRefer interopReferences.EventRegistrationToken.ToValueTypeSignature()]); } + /// + /// Creates a type signature for the get accessor for some delegate handler. + /// + /// The instance to use. + /// The resulting instance. + public static MethodSignature get_Handler(InteropReferences interopReferences) + { + // Signature for 'delegate* unmanaged[MemberFunction]' + return new( + attributes: CallingConventionAttributes.Unmanaged, + returnType: new CustomModifierTypeSignature( + modifierType: interopReferences.CallConvMemberFunction, + isRequired: false, + baseType: interopReferences.CorLibTypeFactory.Int32), + parameterTypes: [ + interopReferences.CorLibTypeFactory.Void.MakePointerType(), + interopReferences.CorLibTypeFactory.Void.MakePointerType().MakePointerType()]); + } + + /// + /// Creates a type signature for the set accessor for some delegate handler. + /// + /// The instance to use. + /// The resulting instance. + public static MethodSignature set_Handler(InteropReferences interopReferences) + { + // Signature for 'delegate* unmanaged[MemberFunction]' + return new( + attributes: CallingConventionAttributes.Unmanaged, + returnType: new CustomModifierTypeSignature( + modifierType: interopReferences.CallConvMemberFunction, + isRequired: false, + baseType: interopReferences.CorLibTypeFactory.Int32), + parameterTypes: [ + interopReferences.CorLibTypeFactory.Void.MakePointerType(), + interopReferences.CorLibTypeFactory.Void.MakePointerType()]); + } + + /// + /// Creates a type signature for the get accessor for some property returning an untyped value (any type). + /// + /// The instance to use. + /// The resulting instance. + public static MethodSignature get_UntypedRetVal(InteropReferences interopReferences) + { + // Signature for 'delegate* unmanaged[MemberFunction]' + return new( + attributes: CallingConventionAttributes.Unmanaged, + returnType: new CustomModifierTypeSignature( + modifierType: interopReferences.CallConvMemberFunction, + isRequired: false, + baseType: interopReferences.CorLibTypeFactory.Int32), + parameterTypes: [ + interopReferences.CorLibTypeFactory.Void.MakePointerType(), + interopReferences.CorLibTypeFactory.Void.MakePointerType()]); + } + /// /// Creates a type signature for the Invoke vtable entry for a delegate, taking objects for both parameters. /// @@ -172,7 +229,7 @@ public static MethodSignature remove_EventHandler(InteropReferences interopRefer /// The resulting instance. public static MethodSignature InvokeImpl(InteropReferences interopReferences) { - // Signature for 'delegate* unmanaged[MemberFunction]' + // Signature for 'delegate* unmanaged[MemberFunction]' return new( attributes: CallingConventionAttributes.Unmanaged, returnType: new CustomModifierTypeSignature( diff --git a/src/WinRT.Interop.Generator/Generation/InteropGenerator.Emit.cs b/src/WinRT.Interop.Generator/Generation/InteropGenerator.Emit.cs index 9a6cfcec9..e2923c28c 100644 --- a/src/WinRT.Interop.Generator/Generation/InteropGenerator.Emit.cs +++ b/src/WinRT.Interop.Generator/Generation/InteropGenerator.Emit.cs @@ -86,36 +86,51 @@ private static void Emit(InteropGeneratorArgs args, InteropGeneratorDiscoverySta args.Token.ThrowIfCancellationRequested(); - // Emit interop types for 'IReadOnlyDictionary<,>' types + // Emit interop types for 'IReadOnlyDictionary' types DefineIReadOnlyDictionaryTypes(args, discoveryState, emitState, interopDefinitions, interopReferences, module); args.Token.ThrowIfCancellationRequested(); - // Emit interop types for 'IDictionary<,>' types + // Emit interop types for 'IDictionary' types DefineIDictionaryTypes(args, discoveryState, emitState, interopDefinitions, interopReferences, module); args.Token.ThrowIfCancellationRequested(); - // Emit interop types for 'KeyValuePair<,>' types + // Emit interop types for 'KeyValuePair' types DefineKeyValuePairTypes(args, discoveryState, interopDefinitions, interopReferences, module); args.Token.ThrowIfCancellationRequested(); - // Emit interop types for 'IMapChangedEventArgs<>' types + // Emit interop types for 'IMapChangedEventArgs' types DefineIMapChangedEventArgsTypes(args, discoveryState, emitState, interopDefinitions, interopReferences, module); args.Token.ThrowIfCancellationRequested(); - // Emit interop types for 'IObservableVector<>' types + // Emit interop types for 'IObservableVector' types DefineIObservableVectorTypes(args, discoveryState, emitState, interopDefinitions, interopReferences, module); args.Token.ThrowIfCancellationRequested(); - // Emit interop types for 'IObservableMap<>' types + // Emit interop types for 'IObservableMap' types DefineIObservableMapTypes(args, discoveryState, emitState, interopDefinitions, interopReferences, module); args.Token.ThrowIfCancellationRequested(); + // Emit interop types for 'IAsyncActionWithProgress' types + DefineIAsyncActionWithProgressTypes(args, discoveryState, emitState, interopDefinitions, interopReferences, module); + + args.Token.ThrowIfCancellationRequested(); + + // Emit interop types for 'IAsyncOperation' types + DefineIAsyncOperationTypes(args, discoveryState, emitState, interopDefinitions, interopReferences, module); + + args.Token.ThrowIfCancellationRequested(); + + // Emit interop types for 'IAsyncOperationWithProgress' types + DefineIAsyncOperationWithProgressTypes(args, discoveryState, emitState, interopDefinitions, interopReferences, module); + + args.Token.ThrowIfCancellationRequested(); + // Emit interop types for SZ array types DefineSzArrayTypes(args, discoveryState, interopDefinitions, interopReferences, module); @@ -354,6 +369,15 @@ private static void DefineGenericDelegateTypes( module: module, eventSourceType: out _); } + else if (SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.AsyncActionProgressHandler1) || + SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.AsyncActionWithProgressCompletedHandler1) || + SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.AsyncOperationCompletedHandler1) || + SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.AsyncOperationProgressHandler2) || + SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.AsyncOperationWithProgressCompletedHandler2)) + { + // We need these marshaller types for the various async type implementations + emitState.TrackTypeDefinition(marshallerType, typeSignature, "Marshaller"); + } } catch (Exception e) when (!e.IsWellKnown) { @@ -1477,6 +1501,321 @@ private static void DefineIObservableMapTypes( } } + /// + /// Defines the interop types for Windows.Foundation.IAsyncActionWithProgress<TProgress> types. + /// + /// + /// + /// The emit state for this invocation. + /// The instance to use. + /// The instance to use. + /// The interop module being built. + private static void DefineIAsyncActionWithProgressTypes( + InteropGeneratorArgs args, + InteropGeneratorDiscoveryState discoveryState, + InteropGeneratorEmitState emitState, + InteropDefinitions interopDefinitions, + InteropReferences interopReferences, + ModuleDefinition module) + { + foreach (GenericInstanceTypeSignature typeSignature in discoveryState.IAsyncActionWithProgress1Types) + { + args.Token.ThrowIfCancellationRequested(); + + try + { + InteropTypeDefinitionBuilder.IAsyncActionWithProgress1.IID( + actionType: typeSignature, + interopDefinitions: interopDefinitions, + interopReferences: interopReferences, + module: module, + get_IidMethod: out MethodDefinition get_IidMethod); + + InteropTypeDefinitionBuilder.IAsyncActionWithProgress1.ImplType( + actionType: typeSignature, + interopDefinitions: interopDefinitions, + interopReferences: interopReferences, + emitState: emitState, + module: module, + implType: out _); + + InteropTypeDefinitionBuilder.IAsyncActionWithProgress1.Methods( + actionType: typeSignature, + interopDefinitions: interopDefinitions, + interopReferences: interopReferences, + emitState: emitState, + module: module, + actionMethodsType: out TypeDefinition actionMethodsType); + + InteropTypeDefinitionBuilder.IAsyncActionWithProgress1.NativeObject( + actionType: typeSignature, + actionMethodsType: actionMethodsType, + interopReferences: interopReferences, + module: module, + out TypeDefinition nativeObjectType); + + InteropTypeDefinitionBuilder.IAsyncActionWithProgress1.ComWrappersCallbackType( + actionType: typeSignature, + nativeObjectType: nativeObjectType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + out TypeDefinition actionComWrappersCallbackType); + + InteropTypeDefinitionBuilder.IAsyncActionWithProgress1.ComWrappersMarshallerAttribute( + actionType: typeSignature, + nativeObjectType: nativeObjectType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + out TypeDefinition actionComWrappersMarshallerType); + + InteropTypeDefinitionBuilder.IAsyncActionWithProgress1.Marshaller( + actionType: typeSignature, + operationComWrappersCallbackType: actionComWrappersCallbackType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + marshallerType: out TypeDefinition marshallerType); + + InteropTypeDefinitionBuilder.IAsyncActionWithProgress1.InterfaceImpl( + actionType: typeSignature, + actionMethodsType: actionMethodsType, + interopReferences: interopReferences, + module: module, + interfaceImplType: out TypeDefinition interfaceImplType); + + InteropTypeDefinitionBuilder.IAsyncActionWithProgress1.Proxy( + actionType: typeSignature, + actionComWrappersMarshallerAttributeType: actionComWrappersMarshallerType, + interopReferences: interopReferences, + module: module, + out TypeDefinition proxyType); + + InteropTypeDefinitionBuilder.IAsyncActionWithProgress1.TypeMapAttributes( + actionType: typeSignature, + proxyType: proxyType, + interfaceImplType: interfaceImplType, + interopReferences: interopReferences, + module: module); + } + catch (Exception e) when (!e.IsWellKnown) + { + throw WellKnownInteropExceptions.IAsyncActionWithProgressTypeCodeGenerationError(typeSignature, e); + } + } + } + + /// + /// Defines the interop types for Windows.Foundation.IAsyncOperation<TResult> types. + /// + /// + /// + /// The emit state for this invocation. + /// The instance to use. + /// The instance to use. + /// The interop module being built. + private static void DefineIAsyncOperationTypes( + InteropGeneratorArgs args, + InteropGeneratorDiscoveryState discoveryState, + InteropGeneratorEmitState emitState, + InteropDefinitions interopDefinitions, + InteropReferences interopReferences, + ModuleDefinition module) + { + foreach (GenericInstanceTypeSignature typeSignature in discoveryState.IAsyncOperation1Types) + { + args.Token.ThrowIfCancellationRequested(); + + try + { + InteropTypeDefinitionBuilder.IAsyncOperation1.IID( + operationType: typeSignature, + interopDefinitions: interopDefinitions, + interopReferences: interopReferences, + module: module, + get_IidMethod: out MethodDefinition get_IidMethod); + + InteropTypeDefinitionBuilder.IAsyncOperation1.ImplType( + operationType: typeSignature, + interopDefinitions: interopDefinitions, + interopReferences: interopReferences, + emitState: emitState, + module: module, + implType: out _); + + InteropTypeDefinitionBuilder.IAsyncOperation1.Methods( + operationType: typeSignature, + interopDefinitions: interopDefinitions, + interopReferences: interopReferences, + emitState: emitState, + module: module, + operationMethodsType: out TypeDefinition operationMethodsType); + + InteropTypeDefinitionBuilder.IAsyncOperation1.NativeObject( + operationType: typeSignature, + operationMethodsType: operationMethodsType, + interopReferences: interopReferences, + module: module, + out TypeDefinition nativeObjectType); + + InteropTypeDefinitionBuilder.IAsyncOperation1.ComWrappersCallbackType( + operationType: typeSignature, + nativeObjectType: nativeObjectType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + out TypeDefinition operationComWrappersCallbackType); + + InteropTypeDefinitionBuilder.IAsyncOperation1.ComWrappersMarshallerAttribute( + operationType: typeSignature, + nativeObjectType: nativeObjectType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + out TypeDefinition operationComWrappersMarshallerType); + + InteropTypeDefinitionBuilder.IAsyncOperation1.Marshaller( + operationType: typeSignature, + operationComWrappersCallbackType: operationComWrappersCallbackType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + marshallerType: out TypeDefinition marshallerType); + + InteropTypeDefinitionBuilder.IAsyncOperation1.InterfaceImpl( + operationType: typeSignature, + operationMethodsType: operationMethodsType, + interopReferences: interopReferences, + module: module, + interfaceImplType: out TypeDefinition interfaceImplType); + + InteropTypeDefinitionBuilder.IAsyncOperation1.Proxy( + operationType: typeSignature, + operationComWrappersMarshallerAttributeType: operationComWrappersMarshallerType, + interopReferences: interopReferences, + module: module, + out TypeDefinition proxyType); + + InteropTypeDefinitionBuilder.IAsyncOperation1.TypeMapAttributes( + operationType: typeSignature, + proxyType: proxyType, + interfaceImplType: interfaceImplType, + interopReferences: interopReferences, + module: module); + } + catch (Exception e) when (!e.IsWellKnown) + { + throw WellKnownInteropExceptions.IAsyncOperationTypeCodeGenerationError(typeSignature, e); + } + } + } + + /// + /// Defines the interop types for Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress> types. + /// + /// + /// + /// The emit state for this invocation. + /// The instance to use. + /// The instance to use. + /// The interop module being built. + private static void DefineIAsyncOperationWithProgressTypes( + InteropGeneratorArgs args, + InteropGeneratorDiscoveryState discoveryState, + InteropGeneratorEmitState emitState, + InteropDefinitions interopDefinitions, + InteropReferences interopReferences, + ModuleDefinition module) + { + foreach (GenericInstanceTypeSignature typeSignature in discoveryState.IAsyncOperationWithProgress2Types) + { + args.Token.ThrowIfCancellationRequested(); + + try + { + InteropTypeDefinitionBuilder.IAsyncOperationWithProgress2.IID( + operationType: typeSignature, + interopDefinitions: interopDefinitions, + interopReferences: interopReferences, + module: module, + get_IidMethod: out MethodDefinition get_IidMethod); + + InteropTypeDefinitionBuilder.IAsyncOperationWithProgress2.ImplType( + operationType: typeSignature, + interopDefinitions: interopDefinitions, + interopReferences: interopReferences, + emitState: emitState, + module: module, + implType: out _); + + InteropTypeDefinitionBuilder.IAsyncOperationWithProgress2.Methods( + operationType: typeSignature, + interopDefinitions: interopDefinitions, + interopReferences: interopReferences, + emitState: emitState, + module: module, + operationMethodsType: out TypeDefinition operationMethodsType); + + InteropTypeDefinitionBuilder.IAsyncOperationWithProgress2.NativeObject( + operationType: typeSignature, + operationMethodsType: operationMethodsType, + interopReferences: interopReferences, + module: module, + out TypeDefinition nativeObjectType); + + InteropTypeDefinitionBuilder.IAsyncOperationWithProgress2.ComWrappersCallbackType( + operationType: typeSignature, + nativeObjectType: nativeObjectType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + out TypeDefinition operationComWrappersCallbackType); + + InteropTypeDefinitionBuilder.IAsyncOperationWithProgress2.ComWrappersMarshallerAttribute( + operationType: typeSignature, + nativeObjectType: nativeObjectType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + out TypeDefinition operationComWrappersMarshallerType); + + InteropTypeDefinitionBuilder.IAsyncOperationWithProgress2.Marshaller( + operationType: typeSignature, + operationComWrappersCallbackType: operationComWrappersCallbackType, + get_IidMethod: get_IidMethod, + interopReferences: interopReferences, + module: module, + marshallerType: out TypeDefinition marshallerType); + + InteropTypeDefinitionBuilder.IAsyncOperationWithProgress2.InterfaceImpl( + operationType: typeSignature, + operationMethodsType: operationMethodsType, + interopReferences: interopReferences, + module: module, + interfaceImplType: out TypeDefinition interfaceImplType); + + InteropTypeDefinitionBuilder.IAsyncOperationWithProgress2.Proxy( + operationType: typeSignature, + operationComWrappersMarshallerAttributeType: operationComWrappersMarshallerType, + interopReferences: interopReferences, + module: module, + out TypeDefinition proxyType); + + InteropTypeDefinitionBuilder.IAsyncOperationWithProgress2.TypeMapAttributes( + operationType: typeSignature, + proxyType: proxyType, + interfaceImplType: interfaceImplType, + interopReferences: interopReferences, + module: module); + } + catch (Exception e) when (!e.IsWellKnown) + { + throw WellKnownInteropExceptions.IAsyncOperationWithProgressTypeCodeGenerationError(typeSignature, e); + } + } + } + /// /// Defines the interop types for SZ array types. /// @@ -1682,6 +2021,9 @@ private static void DefineDefaultImplementationDetailTypes(InteropDefinitions in module.TopLevelTypes.Add(interopDefinitions.IKeyValuePairInterfaceEntries); module.TopLevelTypes.Add(interopDefinitions.IObservableVectorVftbl); module.TopLevelTypes.Add(interopDefinitions.IObservableMapVftbl); + module.TopLevelTypes.Add(interopDefinitions.IAsyncActionWithProgressVftbl); + module.TopLevelTypes.Add(interopDefinitions.IAsyncOperationVftbl); + module.TopLevelTypes.Add(interopDefinitions.IAsyncOperationWithProgressVftbl); module.TopLevelTypes.Add(interopDefinitions.IMapChangedEventArgsVftbl); module.TopLevelTypes.Add(interopDefinitions.IReferenceArrayVftbl); module.TopLevelTypes.Add(interopDefinitions.IReferenceArrayInterfaceEntries); diff --git a/src/WinRT.Interop.Generator/Generation/InteropGeneratorDiscoveryState.cs b/src/WinRT.Interop.Generator/Generation/InteropGeneratorDiscoveryState.cs index dbbacada5..af66f31fd 100644 --- a/src/WinRT.Interop.Generator/Generation/InteropGeneratorDiscoveryState.cs +++ b/src/WinRT.Interop.Generator/Generation/InteropGeneratorDiscoveryState.cs @@ -48,6 +48,15 @@ internal sealed class InteropGeneratorDiscoveryState /// Backing field for . private readonly ConcurrentDictionary _imapChangedEventArgs1Types = new(SignatureComparer.IgnoreVersion); + /// Backing field for . + private readonly ConcurrentDictionary _iasyncActionWithProgress1Types = new(SignatureComparer.IgnoreVersion); + + /// Backing field for . + private readonly ConcurrentDictionary _iasyncOperation1Types = new(SignatureComparer.IgnoreVersion); + + /// Backing field for . + private readonly ConcurrentDictionary _iasyncOperationWithProgress2Types = new(SignatureComparer.IgnoreVersion); + /// Backing field for . private readonly ConcurrentDictionary _genericDelegateTypes = new(SignatureComparer.IgnoreVersion); @@ -133,6 +142,21 @@ internal sealed class InteropGeneratorDiscoveryState /// public IReadOnlyCollection IMapChangedEventArgs1Types => (IReadOnlyCollection)_imapChangedEventArgs1Types.Keys; + /// + /// Gets all Windows.Foundation.IAsyncActionWithProgress<TProgress> types. + /// + public IReadOnlyCollection IAsyncActionWithProgress1Types => (IReadOnlyCollection)_iasyncActionWithProgress1Types.Keys; + + /// + /// Gets all Windows.Foundation.IAsyncOperation<TResult> types. + /// + public IReadOnlyCollection IAsyncOperation1Types => (IReadOnlyCollection)_iasyncOperation1Types.Keys; + + /// + /// Gets all Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress> types. + /// + public IReadOnlyCollection IAsyncOperationWithProgress2Types => (IReadOnlyCollection)_iasyncOperationWithProgress2Types.Keys; + /// /// Gets all generic delegate types. /// @@ -291,6 +315,39 @@ public void TrackIMapChangedEventArgs1Type(GenericInstanceTypeSignature argsType _ = _imapChangedEventArgs1Types.TryAdd(argsType, 0); } + /// + /// Tracks a Windows.Foundation.IAsyncActionWithProgress<TProgress> type. + /// + /// The Windows.Foundation.IAsyncActionWithProgress<TProgress> type. + public void TrackIAsyncActionWithProgress1Type(GenericInstanceTypeSignature actionType) + { + ThrowIfReadOnly(); + + _ = _iasyncActionWithProgress1Types.TryAdd(actionType, 0); + } + + /// + /// Tracks a Windows.Foundation.IAsyncOperation<TResult> type. + /// + /// The Windows.Foundation.IAsyncOperation<TResult> type. + public void TrackIAsyncOperation1Type(GenericInstanceTypeSignature operationType) + { + ThrowIfReadOnly(); + + _ = _iasyncOperation1Types.TryAdd(operationType, 0); + } + + /// + /// Tracks a Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress> type. + /// + /// The Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress> type. + public void TrackIAsyncOperationWithProgress2Type(GenericInstanceTypeSignature operationType) + { + ThrowIfReadOnly(); + + _ = _iasyncOperationWithProgress2Types.TryAdd(operationType, 0); + } + /// /// Tracks a generic delegate type. /// diff --git a/src/WinRT.Interop.Generator/References/InteropDefinitions.cs b/src/WinRT.Interop.Generator/References/InteropDefinitions.cs index f6ca8e88c..cd05a7f7e 100644 --- a/src/WinRT.Interop.Generator/References/InteropDefinitions.cs +++ b/src/WinRT.Interop.Generator/References/InteropDefinitions.cs @@ -143,6 +143,21 @@ public InteropDefinitions(InteropReferences interopReferences, ModuleDefinition /// public TypeDefinition IObservableMapVftbl => field ??= WellKnownTypeDefinitionFactory.IObservableMapVftbl(_interopReferences, _interopModule); + /// + /// Gets the for the IAsyncActionWithProgressVftbl type. + /// + public TypeDefinition IAsyncActionWithProgressVftbl => field ??= WellKnownTypeDefinitionFactory.IAsyncActionWithProgressVftbl(_interopReferences, _interopModule); + + /// + /// Gets the for the IAsyncOperationVftbl type. + /// + public TypeDefinition IAsyncOperationVftbl => field ??= WellKnownTypeDefinitionFactory.IAsyncOperationVftbl(_interopReferences, _interopModule); + + /// + /// Gets the for the IAsyncOperationWithProgressVftbl type. + /// + public TypeDefinition IAsyncOperationWithProgressVftbl => field ??= WellKnownTypeDefinitionFactory.IAsyncOperationWithProgressVftbl(_interopReferences, _interopModule); + /// /// Gets the for the IReferenceArrayVftbl type. /// diff --git a/src/WinRT.Interop.Generator/References/InteropReferences.cs b/src/WinRT.Interop.Generator/References/InteropReferences.cs index 82b78eef5..8a9ca070f 100644 --- a/src/WinRT.Interop.Generator/References/InteropReferences.cs +++ b/src/WinRT.Interop.Generator/References/InteropReferences.cs @@ -431,6 +431,26 @@ public InteropReferences( /// public TypeReference IAgileObjectImpl => field ??= _windowsRuntimeModule.CreateTypeReference("WindowsRuntime.InteropServices"u8, "IAgileObjectImpl"u8); + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncActionWithProgressMethods. + /// + public TypeReference IAsyncActionWithProgressMethods => field ??= _windowsRuntimeModule.CreateTypeReference("WindowsRuntime.InteropServices"u8, "IAsyncActionWithProgressMethods"u8); + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncActionWithProgressMethodsImpl<TProgress>. + /// + public TypeReference IAsyncActionWithProgressMethodsImpl1 => field ??= _windowsRuntimeModule.CreateTypeReference("WindowsRuntime.InteropServices"u8, "IAsyncActionWithProgressMethodsImpl`1"u8); + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncOperationMethodsImpl<TResult>. + /// + public TypeReference IAsyncOperationMethodsImpl1 => field ??= _windowsRuntimeModule.CreateTypeReference("WindowsRuntime.InteropServices"u8, "IAsyncOperationMethodsImpl`1"u8); + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncOperationWithProgressMethodsImpl<TResult, TProgress>. + /// + public TypeReference IAsyncOperationWithProgressMethodsImpl2 => field ??= _windowsRuntimeModule.CreateTypeReference("WindowsRuntime.InteropServices"u8, "IAsyncOperationWithProgressMethodsImpl`2"u8); + /// /// Gets the for WindowsRuntime.InteropServices.IIteratorMethods. /// @@ -536,6 +556,21 @@ public InteropReferences( /// public TypeReference WindowsRuntimeObject => field ??= _windowsRuntimeModule.CreateTypeReference("WindowsRuntime"u8, "WindowsRuntimeObject"u8); + /// + /// Gets the for WindowsRuntime.WindowsRuntimeAsyncActionWithProgress<T, ...>. + /// + public TypeReference WindowsRuntimeAsyncActionWithProgress2 => field ??= _windowsRuntimeModule.CreateTypeReference("WindowsRuntime"u8, "WindowsRuntimeAsyncActionWithProgress`2"u8); + + /// + /// Gets the for WindowsRuntime.WindowsRuntimeAsyncOperation<T, ...>. + /// + public TypeReference WindowsRuntimeAsyncOperation2 => field ??= _windowsRuntimeModule.CreateTypeReference("WindowsRuntime"u8, "WindowsRuntimeAsyncOperation`2"u8); + + /// + /// Gets the for WindowsRuntime.WindowsRuntimeAsyncOperationWithProgress<T, ...>. + /// + public TypeReference WindowsRuntimeAsyncOperationWithProgress3 => field ??= _windowsRuntimeModule.CreateTypeReference("WindowsRuntime"u8, "WindowsRuntimeAsyncOperationWithProgress`3"u8); + /// /// Gets the for WindowsRuntime.WindowsRuntimeEnumerator<T, ...>. /// @@ -751,6 +786,51 @@ public InteropReferences( /// public TypeReference MapChangedEventHandler2EventSource => field ??= _windowsRuntimeModule.CreateTypeReference("WindowsRuntime.InteropServices"u8, "MapChangedEventHandlerEventSource`2"u8); + /// + /// Gets the for Windows.Foundation.IAsyncInfo. + /// + public TypeReference IAsyncInfo => field ??= _windowsSdkProjectionModule.CreateTypeReference("Windows.Foundation"u8, "IAsyncInfo"u8); + + /// + /// Gets the for Windows.Foundation.IAsyncActionWithProgress<TProgress>. + /// + public TypeReference IAsyncActionWithProgress1 => field ??= _windowsSdkProjectionModule.CreateTypeReference("Windows.Foundation"u8, "IAsyncActionWithProgress`1"u8); + + /// + /// Gets the for Windows.Foundation.AsyncActionProgressHandler<TProgress>. + /// + public TypeReference AsyncActionProgressHandler1 => field ??= _windowsSdkProjectionModule.CreateTypeReference("Windows.Foundation"u8, "AsyncActionProgressHandler`1"u8); + + /// + /// Gets the for Windows.Foundation.AsyncActionWithProgressCompletedHandler<TProgress>. + /// + public TypeReference AsyncActionWithProgressCompletedHandler1 => field ??= _windowsSdkProjectionModule.CreateTypeReference("Windows.Foundation"u8, "AsyncActionWithProgressCompletedHandler`1"u8); + + /// + /// Gets the for Windows.Foundation.IAsyncOperation<TResult>. + /// + public TypeReference IAsyncOperation1 => field ??= _windowsSdkProjectionModule.CreateTypeReference("Windows.Foundation"u8, "IAsyncOperation`1"u8); + + /// + /// Gets the for Windows.Foundation.AsyncOperationCompletedHandler<TResult>. + /// + public TypeReference AsyncOperationCompletedHandler1 => field ??= _windowsSdkProjectionModule.CreateTypeReference("Windows.Foundation"u8, "AsyncOperationCompletedHandler`1"u8); + + /// + /// Gets the for Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress>. + /// + public TypeReference IAsyncOperationWithProgress2 => field ??= _windowsSdkProjectionModule.CreateTypeReference("Windows.Foundation"u8, "IAsyncOperationWithProgress`2"u8); + + /// + /// Gets the for Windows.Foundation.AsyncOperationProgressHandler<TResult, TProgress>. + /// + public TypeReference AsyncOperationProgressHandler2 => field ??= _windowsSdkProjectionModule.CreateTypeReference("Windows.Foundation"u8, "AsyncOperationProgressHandler`2"u8); + + /// + /// Gets the for Windows.Foundation.AsyncOperationWithProgressCompletedHandler<TResult>. + /// + public TypeReference AsyncOperationWithProgressCompletedHandler2 => field ??= _windowsSdkProjectionModule.CreateTypeReference("Windows.Foundation"u8, "AsyncOperationWithProgressCompletedHandler`2"u8); + /// /// Gets the for . /// @@ -1078,6 +1158,14 @@ public InteropReferences( public MemberReference WindowsRuntimeObjectReferenceAsValue => field ??= WindowsRuntimeObjectReference .CreateMemberReference("AsValue"u8, MethodSignature.CreateInstance(WindowsRuntimeObjectReferenceValue.ToValueTypeSignature())); + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncActionWithProgress.GetResults(). + /// + public MemberReference IAsyncActionWithProgressGetResults => field ??= IAsyncActionWithProgressMethods + .CreateMemberReference("GetResults"u8, MethodSignature.CreateStatic( + returnType: _corLibTypeFactory.Void, + parameterTypes: [WindowsRuntimeObjectReference.ToReferenceTypeSignature()])); + /// /// Gets the for WindowsRuntime.InteropServices.IIteratorMethods.HasCurrent. /// @@ -1717,6 +1805,395 @@ public MemberReference WindowsRuntimeInterfaceMarshallerConvertToUnmanaged(TypeS Guid.MakeByReferenceType()])); } + /// + /// Gets the for Windows.Foundation.IAsyncActionWithProgress<TProgress>.get_Progress. + /// + /// The input progress type. + public MemberReference IAsyncActionWithProgress1get_Progress(TypeSignature progressType) + { + return IAsyncActionWithProgress1 + .MakeGenericReferenceType(progressType) + .ToTypeDefOrRef() + .CreateMemberReference("get_Progress"u8, MethodSignature.CreateInstance( + returnType: AsyncActionProgressHandler1.MakeGenericReferenceType(new GenericParameterSignature(GenericParameterType.Type, 0)))); + } + + /// + /// Gets the for Windows.Foundation.IAsyncActionWithProgress<TProgress>.set_Progress. + /// + /// The input progress type. + public MemberReference IAsyncActionWithProgress1set_Progress(TypeSignature progressType) + { + return IAsyncActionWithProgress1 + .MakeGenericReferenceType(progressType) + .ToTypeDefOrRef() + .CreateMemberReference("set_Progress"u8, MethodSignature.CreateInstance( + returnType: _corLibTypeFactory.Void, + parameterTypes: [AsyncActionProgressHandler1.MakeGenericReferenceType(new GenericParameterSignature(GenericParameterType.Type, 0))])); + } + + /// + /// Gets the for Windows.Foundation.IAsyncActionWithProgress<TProgress>.get_Completed. + /// + /// The input progress type. + public MemberReference IAsyncActionWithProgress1get_Completed(TypeSignature progressType) + { + return IAsyncActionWithProgress1 + .MakeGenericReferenceType(progressType) + .ToTypeDefOrRef() + .CreateMemberReference("get_Completed"u8, MethodSignature.CreateInstance( + returnType: AsyncActionWithProgressCompletedHandler1.MakeGenericReferenceType(new GenericParameterSignature(GenericParameterType.Type, 0)))); + } + + /// + /// Gets the for Windows.Foundation.IAsyncActionWithProgress<TProgress>.set_Completed. + /// + /// The input progress type. + public MemberReference IAsyncActionWithProgress1set_Completed(TypeSignature progressType) + { + return IAsyncActionWithProgress1 + .MakeGenericReferenceType(progressType) + .ToTypeDefOrRef() + .CreateMemberReference("set_Completed"u8, MethodSignature.CreateInstance( + returnType: _corLibTypeFactory.Void, + parameterTypes: [AsyncActionWithProgressCompletedHandler1.MakeGenericReferenceType(new GenericParameterSignature(GenericParameterType.Type, 0))])); + } + + /// + /// Gets the for Windows.Foundation.IAsyncActionWithProgress<TProgress>.GetResults. + /// + /// The input progress type. + public MemberReference IAsyncActionWithProgress1GetResults(TypeSignature progressType) + { + return IAsyncActionWithProgress1 + .MakeGenericReferenceType(progressType) + .ToTypeDefOrRef() + .CreateMemberReference("GetResults"u8, MethodSignature.CreateInstance(_corLibTypeFactory.Void)); + } + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncActionWithProgressMethodsImpl<TProgress>.Progress. + /// + /// The input progress type. + public MemberReference IAsyncActionWithProgressMethodsImpl1get_Progress(TypeSignature progressType) + { + return IAsyncActionWithProgressMethodsImpl1 + .MakeGenericReferenceType(progressType) + .ToTypeDefOrRef() + .CreateMemberReference("Progress"u8, MethodSignature.CreateInstance( + returnType: AsyncActionProgressHandler1.MakeGenericReferenceType(new GenericParameterSignature(GenericParameterType.Type, 0)), + parameterTypes: [WindowsRuntimeObjectReference.ToReferenceTypeSignature()])); + } + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncActionWithProgressMethodsImpl<TProgress>.Progress. + /// + /// The input result type. + public MemberReference IAsyncActionWithProgressMethodsImpl1set_Progress(TypeSignature resultType) + { + return IAsyncActionWithProgressMethodsImpl1 + .MakeGenericReferenceType(resultType) + .ToTypeDefOrRef() + .CreateMemberReference("Progress"u8, MethodSignature.CreateInstance( + returnType: _corLibTypeFactory.Void, + parameterTypes: [ + WindowsRuntimeObjectReference.ToReferenceTypeSignature(), + AsyncActionProgressHandler1.MakeGenericReferenceType(new GenericParameterSignature(GenericParameterType.Type, 0))])); + } + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncActionWithProgressMethodsImpl<TProgress>.Completed. + /// + /// The input progress type. + public MemberReference IAsyncActionWithProgressMethodsImpl1get_Completed(TypeSignature progressType) + { + return IAsyncActionWithProgressMethodsImpl1 + .MakeGenericReferenceType(progressType) + .ToTypeDefOrRef() + .CreateMemberReference("Completed"u8, MethodSignature.CreateInstance( + returnType: AsyncActionWithProgressCompletedHandler1.MakeGenericReferenceType(new GenericParameterSignature(GenericParameterType.Type, 0)), + parameterTypes: [WindowsRuntimeObjectReference.ToReferenceTypeSignature()])); + } + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncActionWithProgressMethodsImpl<TProgress>.Completed. + /// + /// The input result type. + public MemberReference IAsyncActionWithProgressMethodsImpl1set_Completed(TypeSignature resultType) + { + return IAsyncActionWithProgressMethodsImpl1 + .MakeGenericReferenceType(resultType) + .ToTypeDefOrRef() + .CreateMemberReference("Completed"u8, MethodSignature.CreateInstance( + returnType: _corLibTypeFactory.Void, + parameterTypes: [ + WindowsRuntimeObjectReference.ToReferenceTypeSignature(), + AsyncActionWithProgressCompletedHandler1.MakeGenericReferenceType(new GenericParameterSignature(GenericParameterType.Type, 0))])); + } + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncActionWithProgressMethodsImpl<TProgress>.GetResults(). + /// + /// The input result type. + public MemberReference IAsyncActionWithProgressMethodsImpl1GetResults(TypeSignature resultType) + { + return IAsyncActionWithProgressMethodsImpl1 + .MakeGenericReferenceType(resultType) + .ToTypeDefOrRef() + .CreateMemberReference("GetResults"u8, MethodSignature.CreateInstance( + returnType: _corLibTypeFactory.Void, + parameterTypes: [WindowsRuntimeObjectReference.ToReferenceTypeSignature()])); + } + + /// + /// Gets the for Windows.Foundation.IAsyncOperation<TResult>.get_Completed. + /// + /// The input result type. + public MemberReference IAsyncOperation1get_Completed(TypeSignature resultType) + { + return IAsyncOperation1 + .MakeGenericReferenceType(resultType) + .ToTypeDefOrRef() + .CreateMemberReference("get_Completed"u8, MethodSignature.CreateInstance( + returnType: AsyncOperationCompletedHandler1.MakeGenericReferenceType(new GenericParameterSignature(GenericParameterType.Type, 0)))); + } + + /// + /// Gets the for Windows.Foundation.IAsyncOperation<TResult>.set_Completed. + /// + /// The input element type. + public MemberReference IAsyncOperation1set_Completed(TypeSignature resultType) + { + return IAsyncOperation1 + .MakeGenericReferenceType(resultType) + .ToTypeDefOrRef() + .CreateMemberReference("set_Completed"u8, MethodSignature.CreateInstance( + returnType: _corLibTypeFactory.Void, + parameterTypes: [AsyncOperationCompletedHandler1.MakeGenericReferenceType(new GenericParameterSignature(GenericParameterType.Type, 0))])); + } + + /// + /// Gets the for Windows.Foundation.IAsyncOperation<TResult>.GetResults. + /// + /// The input element type. + public MemberReference IAsyncOperation1GetResults(TypeSignature resultType) + { + return IAsyncOperation1 + .MakeGenericReferenceType(resultType) + .ToTypeDefOrRef() + .CreateMemberReference("GetResults"u8, MethodSignature.CreateInstance(resultType)); + } + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncOperationMethodsImpl<TResult>.Completed. + /// + /// The input result type. + public MemberReference IAsyncOperationMethodsImpl1get_Completed(TypeSignature resultType) + { + return IAsyncOperationMethodsImpl1 + .MakeGenericReferenceType(resultType) + .ToTypeDefOrRef() + .CreateMemberReference("Completed"u8, MethodSignature.CreateInstance( + returnType: AsyncOperationCompletedHandler1.MakeGenericReferenceType(new GenericParameterSignature(GenericParameterType.Type, 0)), + parameterTypes: [WindowsRuntimeObjectReference.ToReferenceTypeSignature()])); + } + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncOperationMethodsImpl<TResult>.Completed. + /// + /// The input result type. + public MemberReference IAsyncOperationMethodsImpl1set_Completed(TypeSignature resultType) + { + return IAsyncOperationMethodsImpl1 + .MakeGenericReferenceType(resultType) + .ToTypeDefOrRef() + .CreateMemberReference("Completed"u8, MethodSignature.CreateInstance( + returnType: _corLibTypeFactory.Void, + parameterTypes: [ + WindowsRuntimeObjectReference.ToReferenceTypeSignature(), + AsyncOperationCompletedHandler1.MakeGenericReferenceType(new GenericParameterSignature(GenericParameterType.Type, 0))])); + } + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncOperationMethodsImpl<TResult>.GetResults. + /// + /// The input result type. + public MemberReference IAsyncOperationMethodsImpl1GetResults(TypeSignature resultType) + { + return IAsyncOperationMethodsImpl1 + .MakeGenericReferenceType(resultType) + .ToTypeDefOrRef() + .CreateMemberReference("GetResults"u8, MethodSignature.CreateInstance( + returnType: new GenericParameterSignature(GenericParameterType.Type, 0), + parameterTypes: [WindowsRuntimeObjectReference.ToReferenceTypeSignature()])); + } + + /// + /// Gets the for Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress>.get_Progress. + /// + /// The input result type. + /// The input progress type. + public MemberReference IAsyncOperationWithProgress2get_Progress(TypeSignature resultType, TypeSignature progressType) + { + return IAsyncOperationWithProgress2 + .MakeGenericReferenceType(resultType, progressType) + .ToTypeDefOrRef() + .CreateMemberReference("get_Progress"u8, MethodSignature.CreateInstance( + returnType: AsyncOperationProgressHandler2.MakeGenericReferenceType( + new GenericParameterSignature(GenericParameterType.Type, 0), + new GenericParameterSignature(GenericParameterType.Type, 1)))); + } + + /// + /// Gets the for Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress>.set_Progress. + /// + /// The input result type. + /// The input progress type. + public MemberReference IAsyncOperationWithProgress2set_Progress(TypeSignature resultType, TypeSignature progressType) + { + return IAsyncOperationWithProgress2 + .MakeGenericReferenceType(resultType, progressType) + .ToTypeDefOrRef() + .CreateMemberReference("set_Progress"u8, MethodSignature.CreateInstance( + returnType: _corLibTypeFactory.Void, + parameterTypes: [AsyncOperationProgressHandler2.MakeGenericReferenceType( + new GenericParameterSignature(GenericParameterType.Type, 0), + new GenericParameterSignature(GenericParameterType.Type, 1))])); + } + + /// + /// Gets the for Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress>.get_Completed. + /// + /// The input result type. + /// The input progress type. + public MemberReference IAsyncOperationWithProgress2get_Completed(TypeSignature resultType, TypeSignature progressType) + { + return IAsyncOperationWithProgress2 + .MakeGenericReferenceType(resultType, progressType) + .ToTypeDefOrRef() + .CreateMemberReference("get_Completed"u8, MethodSignature.CreateInstance( + returnType: AsyncOperationWithProgressCompletedHandler2.MakeGenericReferenceType( + new GenericParameterSignature(GenericParameterType.Type, 0), + new GenericParameterSignature(GenericParameterType.Type, 1)))); + } + + /// + /// Gets the for Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress>.set_Completed. + /// + /// The input result type. + /// The input progress type. + public MemberReference IAsyncOperationWithProgress2set_Completed(TypeSignature resultType, TypeSignature progressType) + { + return IAsyncOperationWithProgress2 + .MakeGenericReferenceType(resultType, progressType) + .ToTypeDefOrRef() + .CreateMemberReference("set_Completed"u8, MethodSignature.CreateInstance( + returnType: _corLibTypeFactory.Void, + parameterTypes: [AsyncOperationWithProgressCompletedHandler2.MakeGenericReferenceType( + new GenericParameterSignature(GenericParameterType.Type, 0), + new GenericParameterSignature(GenericParameterType.Type, 1))])); + } + + /// + /// Gets the for Windows.Foundation.IAsyncOperationWithProgress<TResult, TProgress>.GetResults. + /// + /// The input result type. + /// The input progress type. + public MemberReference IAsyncOperationWithProgress2GetResults(TypeSignature resultType, TypeSignature progressType) + { + return IAsyncOperationWithProgress2 + .MakeGenericReferenceType(resultType, progressType) + .ToTypeDefOrRef() + .CreateMemberReference("GetResults"u8, MethodSignature.CreateInstance(new GenericParameterSignature(GenericParameterType.Type, 0))); + } + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncOperationWithProgressMethodsImpl<TResult, TProgress>.Progress. + /// + /// The input result type. + /// The input progress type. + public MemberReference IAsyncOperationWithProgressMethodsImpl2get_Progress(TypeSignature resultType, TypeSignature progressType) + { + return IAsyncOperationWithProgressMethodsImpl2 + .MakeGenericReferenceType(resultType, progressType) + .ToTypeDefOrRef() + .CreateMemberReference("Progress"u8, MethodSignature.CreateInstance( + returnType: AsyncOperationProgressHandler2.MakeGenericReferenceType( + new GenericParameterSignature(GenericParameterType.Type, 0), + new GenericParameterSignature(GenericParameterType.Type, 1)), + parameterTypes: [WindowsRuntimeObjectReference.ToReferenceTypeSignature()])); + } + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncOperationWithProgressMethodsImpl<TResult, TProgress>.Progress. + /// + /// The input result type. + /// The input progress type. + public MemberReference IAsyncOperationWithProgressMethodsImpl2set_Progress(TypeSignature resultType, TypeSignature progressType) + { + return IAsyncOperationWithProgressMethodsImpl2 + .MakeGenericReferenceType(resultType, progressType) + .ToTypeDefOrRef() + .CreateMemberReference("Progress"u8, MethodSignature.CreateInstance( + returnType: _corLibTypeFactory.Void, + parameterTypes: [ + WindowsRuntimeObjectReference.ToReferenceTypeSignature(), + AsyncOperationProgressHandler2.MakeGenericReferenceType( + new GenericParameterSignature(GenericParameterType.Type, 0), + new GenericParameterSignature(GenericParameterType.Type, 1))])); + } + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncOperationWithProgressMethodsImpl<TResult, TProgress>.Completed. + /// + /// The input result type. + /// The input progress type. + public MemberReference IAsyncOperationWithProgressMethodsImpl2get_Completed(TypeSignature resultType, TypeSignature progressType) + { + return IAsyncOperationWithProgressMethodsImpl2 + .MakeGenericReferenceType(resultType, progressType) + .ToTypeDefOrRef() + .CreateMemberReference("Completed"u8, MethodSignature.CreateInstance( + returnType: AsyncOperationWithProgressCompletedHandler2.MakeGenericReferenceType( + new GenericParameterSignature(GenericParameterType.Type, 0), + new GenericParameterSignature(GenericParameterType.Type, 1)), + parameterTypes: [WindowsRuntimeObjectReference.ToReferenceTypeSignature()])); + } + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncOperationWithProgressMethodsImpl<TResult, TProgress>.Completed. + /// + /// The input result type. + /// The input progress type. + public MemberReference IAsyncOperationWithProgressMethodsImpl2set_Completed(TypeSignature resultType, TypeSignature progressType) + { + return IAsyncOperationWithProgressMethodsImpl2 + .MakeGenericReferenceType(resultType, progressType) + .ToTypeDefOrRef() + .CreateMemberReference("Completed"u8, MethodSignature.CreateInstance( + returnType: _corLibTypeFactory.Void, + parameterTypes: [ + WindowsRuntimeObjectReference.ToReferenceTypeSignature(), + AsyncOperationWithProgressCompletedHandler2.MakeGenericReferenceType( + new GenericParameterSignature(GenericParameterType.Type, 0), + new GenericParameterSignature(GenericParameterType.Type, 1))])); + } + + /// + /// Gets the for WindowsRuntime.InteropServices.IAsyncOperationWithProgressMethodsImpl<TResult, TProgress>.GetResults(). + /// + /// The input result type. + /// The input progress type. + public MemberReference IAsyncOperationWithProgressMethodsImpl2GetResults(TypeSignature resultType, TypeSignature progressType) + { + return IAsyncOperationWithProgressMethodsImpl2 + .MakeGenericReferenceType(resultType, progressType) + .ToTypeDefOrRef() + .CreateMemberReference("GetResults"u8, MethodSignature.CreateInstance( + returnType: new GenericParameterSignature(GenericParameterType.Type, 0), + parameterTypes: [WindowsRuntimeObjectReference.ToReferenceTypeSignature()])); + } + /// /// Gets the for WindowsRuntime.InteropServices.IEnumeratorAdapter<T>.GetInstance. /// diff --git a/src/WinRT.Runtime2/AsyncInfo/WindowsRuntimeAsyncAction.cs b/src/WinRT.Runtime2/AsyncInfo/WindowsRuntimeAsyncAction.cs index af4cbfcb9..db0c605ba 100644 --- a/src/WinRT.Runtime2/AsyncInfo/WindowsRuntimeAsyncAction.cs +++ b/src/WinRT.Runtime2/AsyncInfo/WindowsRuntimeAsyncAction.cs @@ -15,7 +15,10 @@ namespace WindowsRuntime.AsyncInfo; /// The implementation of a native object for . /// /// -internal sealed class WindowsRuntimeAsyncAction : WindowsRuntimeObject, IAsyncAction, IWindowsRuntimeInterface +internal sealed class WindowsRuntimeAsyncAction : WindowsRuntimeObject, + IAsyncAction, + IWindowsRuntimeInterface, + IWindowsRuntimeInterface { /// /// Creates a instance with the specified parameters. @@ -95,6 +98,12 @@ WindowsRuntimeObjectReferenceValue IWindowsRuntimeInterface.GetInt return NativeObjectReference.AsValue(); } + /// + WindowsRuntimeObjectReferenceValue IWindowsRuntimeInterface.GetInterface() + { + return IAsyncInfoObjectReference.AsValue(); + } + /// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, diff --git a/src/WinRT.Runtime2/AsyncInfo/WindowsRuntimeAsyncActionWithProgress{TProgress}.cs b/src/WinRT.Runtime2/AsyncInfo/WindowsRuntimeAsyncActionWithProgress{TProgress}.cs new file mode 100644 index 000000000..b7c30fb6e --- /dev/null +++ b/src/WinRT.Runtime2/AsyncInfo/WindowsRuntimeAsyncActionWithProgress{TProgress}.cs @@ -0,0 +1,129 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Threading; +using ABI.Windows.Foundation; +using Windows.Foundation; +using WindowsRuntime.InteropServices; + +namespace WindowsRuntime.AsyncInfo; + +/// +/// The implementation of a native object for . +/// +/// The type of progress information. +/// The implementation type. +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public abstract class WindowsRuntimeAsyncActionWithProgress : WindowsRuntimeObject, + IAsyncActionWithProgress, + IWindowsRuntimeInterface>, + IWindowsRuntimeInterface + where TIAsyncActionWithProgressMethods : IAsyncActionWithProgressMethodsImpl +{ + /// + /// Creates a instance with the specified parameters. + /// + /// The inner Windows Runtime object reference to wrap in the current instance. + /// Thrown if is . + protected WindowsRuntimeAsyncActionWithProgress(WindowsRuntimeObjectReference nativeObjectReference) + : base(nativeObjectReference) + { + } + + /// + private WindowsRuntimeObjectReference IAsyncInfoObjectReference + { + get + { + [MethodImpl(MethodImplOptions.NoInlining)] + WindowsRuntimeObjectReference InitializeIAsyncInfoObjectReference() + { + _ = Interlocked.CompareExchange( + location1: ref field, + value: NativeObjectReference.As(in WellKnownWindowsInterfaceIIDs.IID_IAsyncInfo), + comparand: null); + + return field; + } + + return field ?? InitializeIAsyncInfoObjectReference(); + } + } + + /// + [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] + [EditorBrowsable(EditorBrowsableState.Never)] + protected internal override bool HasUnwrappableNativeObjectReference => true; + + /// + public AsyncActionProgressHandler? Progress + { + get => TIAsyncActionWithProgressMethods.Progress(NativeObjectReference); + set => TIAsyncActionWithProgressMethods.Progress(NativeObjectReference, value); + } + + /// + public AsyncActionWithProgressCompletedHandler? Completed + { + get => TIAsyncActionWithProgressMethods.Completed(NativeObjectReference); + set => TIAsyncActionWithProgressMethods.Completed(NativeObjectReference, value); + } + + /// + public uint Id => IAsyncInfoMethods.Id(IAsyncInfoObjectReference); + + /// + public AsyncStatus Status => IAsyncInfoMethods.Status(IAsyncInfoObjectReference); + + /// + public Exception? ErrorCode => IAsyncInfoMethods.ErrorCode(IAsyncInfoObjectReference); + + /// + public void GetResults() + { + IAsyncActionWithProgressMethods.GetResults(NativeObjectReference); + } + + /// + public void Cancel() + { + IAsyncInfoMethods.Cancel(IAsyncInfoObjectReference); + } + + /// + public void Close() + { + IAsyncInfoMethods.Close(IAsyncInfoObjectReference); + } + + /// + WindowsRuntimeObjectReferenceValue IWindowsRuntimeInterface>.GetInterface() + { + return NativeObjectReference.AsValue(); + } + + /// + WindowsRuntimeObjectReferenceValue IWindowsRuntimeInterface.GetInterface() + { + return IAsyncInfoObjectReference.AsValue(); + } + + /// + [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] + [EditorBrowsable(EditorBrowsableState.Never)] + protected override bool IsOverridableInterface(in Guid iid) + { + return false; + } +} diff --git a/src/WinRT.Runtime2/AsyncInfo/WindowsRuntimeAsyncOperationWithProgress{TResult, TProgress}.cs b/src/WinRT.Runtime2/AsyncInfo/WindowsRuntimeAsyncOperationWithProgress{TResult, TProgress}.cs new file mode 100644 index 000000000..2e198d017 --- /dev/null +++ b/src/WinRT.Runtime2/AsyncInfo/WindowsRuntimeAsyncOperationWithProgress{TResult, TProgress}.cs @@ -0,0 +1,130 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Threading; +using ABI.Windows.Foundation; +using Windows.Foundation; +using WindowsRuntime.InteropServices; + +namespace WindowsRuntime.AsyncInfo; + +/// +/// The implementation of a native object for . +/// +/// The result type. +/// The type of progress information. +/// The implementation type. +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public abstract class WindowsRuntimeAsyncOperationWithProgress : WindowsRuntimeObject, + IAsyncOperationWithProgress, + IWindowsRuntimeInterface>, + IWindowsRuntimeInterface + where TIAsyncOperationWithProgressMethods : IAsyncOperationWithProgressMethodsImpl +{ + /// + /// Creates a instance with the specified parameters. + /// + /// The inner Windows Runtime object reference to wrap in the current instance. + /// Thrown if is . + protected WindowsRuntimeAsyncOperationWithProgress(WindowsRuntimeObjectReference nativeObjectReference) + : base(nativeObjectReference) + { + } + + /// + private WindowsRuntimeObjectReference IAsyncInfoObjectReference + { + get + { + [MethodImpl(MethodImplOptions.NoInlining)] + WindowsRuntimeObjectReference InitializeIAsyncInfoObjectReference() + { + _ = Interlocked.CompareExchange( + location1: ref field, + value: NativeObjectReference.As(in WellKnownWindowsInterfaceIIDs.IID_IAsyncInfo), + comparand: null); + + return field; + } + + return field ?? InitializeIAsyncInfoObjectReference(); + } + } + + /// + [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] + [EditorBrowsable(EditorBrowsableState.Never)] + protected internal override bool HasUnwrappableNativeObjectReference => true; + + /// + public AsyncOperationProgressHandler? Progress + { + get => TIAsyncOperationWithProgressMethods.Progress(NativeObjectReference); + set => TIAsyncOperationWithProgressMethods.Progress(NativeObjectReference, value); + } + + /// + public AsyncOperationWithProgressCompletedHandler? Completed + { + get => TIAsyncOperationWithProgressMethods.Completed(NativeObjectReference); + set => TIAsyncOperationWithProgressMethods.Completed(NativeObjectReference, value); + } + + /// + public uint Id => IAsyncInfoMethods.Id(IAsyncInfoObjectReference); + + /// + public AsyncStatus Status => IAsyncInfoMethods.Status(IAsyncInfoObjectReference); + + /// + public Exception? ErrorCode => IAsyncInfoMethods.ErrorCode(IAsyncInfoObjectReference); + + /// + public TResult GetResults() + { + return TIAsyncOperationWithProgressMethods.GetResults(NativeObjectReference); + } + + /// + public void Cancel() + { + IAsyncInfoMethods.Cancel(IAsyncInfoObjectReference); + } + + /// + public void Close() + { + IAsyncInfoMethods.Close(IAsyncInfoObjectReference); + } + + /// + WindowsRuntimeObjectReferenceValue IWindowsRuntimeInterface>.GetInterface() + { + return NativeObjectReference.AsValue(); + } + + /// + WindowsRuntimeObjectReferenceValue IWindowsRuntimeInterface.GetInterface() + { + return IAsyncInfoObjectReference.AsValue(); + } + + /// + [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] + [EditorBrowsable(EditorBrowsableState.Never)] + protected override bool IsOverridableInterface(in Guid iid) + { + return false; + } +} diff --git a/src/WinRT.Runtime2/AsyncInfo/WindowsRuntimeAsyncOperation{TResult}.cs b/src/WinRT.Runtime2/AsyncInfo/WindowsRuntimeAsyncOperation{TResult}.cs new file mode 100644 index 000000000..e89c8e30c --- /dev/null +++ b/src/WinRT.Runtime2/AsyncInfo/WindowsRuntimeAsyncOperation{TResult}.cs @@ -0,0 +1,122 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Threading; +using ABI.Windows.Foundation; +using Windows.Foundation; +using WindowsRuntime.InteropServices; + +namespace WindowsRuntime.AsyncInfo; + +/// +/// The implementation of a native object for . +/// +/// The result type. +/// The implementation type. +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public abstract class WindowsRuntimeAsyncOperation : WindowsRuntimeObject, + IAsyncOperation, + IWindowsRuntimeInterface>, + IWindowsRuntimeInterface + where TIAsyncOperationMethods : IAsyncOperationMethodsImpl +{ + /// + /// Creates a instance with the specified parameters. + /// + /// The inner Windows Runtime object reference to wrap in the current instance. + /// Thrown if is . + protected WindowsRuntimeAsyncOperation(WindowsRuntimeObjectReference nativeObjectReference) + : base(nativeObjectReference) + { + } + + /// + private WindowsRuntimeObjectReference IAsyncInfoObjectReference + { + get + { + [MethodImpl(MethodImplOptions.NoInlining)] + WindowsRuntimeObjectReference InitializeIAsyncInfoObjectReference() + { + _ = Interlocked.CompareExchange( + location1: ref field, + value: NativeObjectReference.As(in WellKnownWindowsInterfaceIIDs.IID_IAsyncInfo), + comparand: null); + + return field; + } + + return field ?? InitializeIAsyncInfoObjectReference(); + } + } + + /// + [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] + [EditorBrowsable(EditorBrowsableState.Never)] + protected internal override bool HasUnwrappableNativeObjectReference => true; + + /// + public AsyncOperationCompletedHandler? Completed + { + get => TIAsyncOperationMethods.Completed(NativeObjectReference); + set => TIAsyncOperationMethods.Completed(NativeObjectReference, value); + } + + /// + public uint Id => IAsyncInfoMethods.Id(IAsyncInfoObjectReference); + + /// + public AsyncStatus Status => IAsyncInfoMethods.Status(IAsyncInfoObjectReference); + + /// + public Exception? ErrorCode => IAsyncInfoMethods.ErrorCode(IAsyncInfoObjectReference); + + /// + public TResult GetResults() + { + return TIAsyncOperationMethods.GetResults(NativeObjectReference); + } + + /// + public void Cancel() + { + IAsyncInfoMethods.Cancel(IAsyncInfoObjectReference); + } + + /// + public void Close() + { + IAsyncInfoMethods.Close(IAsyncInfoObjectReference); + } + + /// + WindowsRuntimeObjectReferenceValue IWindowsRuntimeInterface>.GetInterface() + { + return NativeObjectReference.AsValue(); + } + + /// + WindowsRuntimeObjectReferenceValue IWindowsRuntimeInterface.GetInterface() + { + return IAsyncInfoObjectReference.AsValue(); + } + + /// + [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] + [EditorBrowsable(EditorBrowsableState.Never)] + protected override bool IsOverridableInterface(in Guid iid) + { + return false; + } +} diff --git a/src/WinRT.Runtime2/Collections/DictionaryKeyCollection{TKey, TValue}.cs b/src/WinRT.Runtime2/Collections/DictionaryKeyCollection{TKey, TValue}.cs index d28c25491..49117a7cb 100644 --- a/src/WinRT.Runtime2/Collections/DictionaryKeyCollection{TKey, TValue}.cs +++ b/src/WinRT.Runtime2/Collections/DictionaryKeyCollection{TKey, TValue}.cs @@ -13,9 +13,6 @@ namespace WindowsRuntime; /// /// The type of keys in the dictionary. /// The type of values in the dictionary. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/Collections/DictionaryValueCollection{TKey, TValue}.cs b/src/WinRT.Runtime2/Collections/DictionaryValueCollection{TKey, TValue}.cs index 4c2e91598..d4f9d9c4c 100644 --- a/src/WinRT.Runtime2/Collections/DictionaryValueCollection{TKey, TValue}.cs +++ b/src/WinRT.Runtime2/Collections/DictionaryValueCollection{TKey, TValue}.cs @@ -13,9 +13,6 @@ namespace WindowsRuntime; /// /// The type of keys in the dictionary. /// The type of values in the dictionary. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryKeyCollection{TKey, TValue}.cs b/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryKeyCollection{TKey, TValue}.cs index f314f8892..b99c58bf1 100644 --- a/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryKeyCollection{TKey, TValue}.cs +++ b/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryKeyCollection{TKey, TValue}.cs @@ -13,9 +13,6 @@ namespace WindowsRuntime; /// /// The type of keys in the read-only dictionary. /// The type of values in the read-only dictionary. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryValueCollection{TKey, TValue}.cs b/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryValueCollection{TKey, TValue}.cs index d9e4e6f16..c3190d4fd 100644 --- a/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryValueCollection{TKey, TValue}.cs +++ b/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryValueCollection{TKey, TValue}.cs @@ -13,9 +13,6 @@ namespace WindowsRuntime; /// /// The type of keys in the read-only dictionary. /// The type of values in the read-only dictionary. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/Collections/WindowsRuntimeDictionary{TKey, TValue}.cs b/src/WinRT.Runtime2/Collections/WindowsRuntimeDictionary{TKey, TValue}.cs index 417ac32fd..f70041686 100644 --- a/src/WinRT.Runtime2/Collections/WindowsRuntimeDictionary{TKey, TValue}.cs +++ b/src/WinRT.Runtime2/Collections/WindowsRuntimeDictionary{TKey, TValue}.cs @@ -20,9 +20,6 @@ namespace WindowsRuntime; /// The interface type. /// The Windows.Foundation.Collections.IIterable<T> implementation type. /// The Windows.Foundation.Collections.IMap<K, V> implementation type. -/// -/// This type should only be used as a base type by generated generic instantiations. -/// /// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, diff --git a/src/WinRT.Runtime2/Collections/WindowsRuntimeEnumerable{T}.cs b/src/WinRT.Runtime2/Collections/WindowsRuntimeEnumerable{T}.cs index e5f4aaeef..75bd6205d 100644 --- a/src/WinRT.Runtime2/Collections/WindowsRuntimeEnumerable{T}.cs +++ b/src/WinRT.Runtime2/Collections/WindowsRuntimeEnumerable{T}.cs @@ -16,9 +16,6 @@ namespace WindowsRuntime; /// /// The type of objects to enumerate. /// The Windows.Foundation.Collections.IIterable<T> implementation type. -/// -/// This type should only be used as a base type by generated generic instantiations. -/// /// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, diff --git a/src/WinRT.Runtime2/Collections/WindowsRuntimeEnumerator{T}.cs b/src/WinRT.Runtime2/Collections/WindowsRuntimeEnumerator{T}.cs index ff1b37813..fa64f2437 100644 --- a/src/WinRT.Runtime2/Collections/WindowsRuntimeEnumerator{T}.cs +++ b/src/WinRT.Runtime2/Collections/WindowsRuntimeEnumerator{T}.cs @@ -17,9 +17,6 @@ namespace WindowsRuntime; /// /// The type of objects to enumerate. /// The implementation type. -/// -/// This type should only be used as a base type by generated generic instantiations. -/// /// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, diff --git a/src/WinRT.Runtime2/Collections/WindowsRuntimeList{T}.cs b/src/WinRT.Runtime2/Collections/WindowsRuntimeList{T}.cs index 2bb006dbd..35766b00d 100644 --- a/src/WinRT.Runtime2/Collections/WindowsRuntimeList{T}.cs +++ b/src/WinRT.Runtime2/Collections/WindowsRuntimeList{T}.cs @@ -20,9 +20,6 @@ namespace WindowsRuntime; /// The Windows.Foundation.Collections.IIterable<T> interface type. /// The Windows.Foundation.Collections.IIterable<T> implementation type. /// The Windows.Foundation.Collections.IVector<T> implementation type. -/// -/// This type should only be used as a base type by generated generic instantiations. -/// /// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, diff --git a/src/WinRT.Runtime2/Collections/WindowsRuntimeMapChangedEventArgs{TKey}.cs b/src/WinRT.Runtime2/Collections/WindowsRuntimeMapChangedEventArgs{TKey}.cs index e4793a93c..d19ebbf35 100644 --- a/src/WinRT.Runtime2/Collections/WindowsRuntimeMapChangedEventArgs{TKey}.cs +++ b/src/WinRT.Runtime2/Collections/WindowsRuntimeMapChangedEventArgs{TKey}.cs @@ -13,9 +13,6 @@ namespace WindowsRuntime; /// /// The type of keys in the map. /// The Windows.Foundation.Collections.IMapChangedEventArgs<K> implementation type. -/// -/// This type should only be used as a base type by generated generic instantiations. -/// /// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, diff --git a/src/WinRT.Runtime2/Collections/WindowsRuntimeObservableMap{TKey, TValue}.cs b/src/WinRT.Runtime2/Collections/WindowsRuntimeObservableMap{TKey, TValue}.cs index 53fb5260e..86920eb4b 100644 --- a/src/WinRT.Runtime2/Collections/WindowsRuntimeObservableMap{TKey, TValue}.cs +++ b/src/WinRT.Runtime2/Collections/WindowsRuntimeObservableMap{TKey, TValue}.cs @@ -25,9 +25,6 @@ namespace WindowsRuntime; /// The Windows.Foundation.Collections.IMap<K, V> interface type. /// The Windows.Foundation.Collections.IMap<K, V> implementation type. /// The Windows.Foundation.Collections.IObservableMap<K, V> implementation type. -/// -/// This type should only be used as a base type by generated generic instantiations. -/// /// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, diff --git a/src/WinRT.Runtime2/Collections/WindowsRuntimeObservableVector{T}.cs b/src/WinRT.Runtime2/Collections/WindowsRuntimeObservableVector{T}.cs index bc1bf7a0d..afb33e6c5 100644 --- a/src/WinRT.Runtime2/Collections/WindowsRuntimeObservableVector{T}.cs +++ b/src/WinRT.Runtime2/Collections/WindowsRuntimeObservableVector{T}.cs @@ -23,9 +23,6 @@ namespace WindowsRuntime; /// The Windows.Foundation.Collections.IVector<T> interface type. /// The Windows.Foundation.Collections.IVector<T> implementation type. /// The Windows.Foundation.Collections.IObservableVector<T> implementation type. -/// -/// This type should only be used as a base type by generated generic instantiations. -/// /// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, diff --git a/src/WinRT.Runtime2/Collections/WindowsRuntimeReadOnlyDictionary{TKey, TValue}.cs b/src/WinRT.Runtime2/Collections/WindowsRuntimeReadOnlyDictionary{TKey, TValue}.cs index 175f892f6..86e053dd5 100644 --- a/src/WinRT.Runtime2/Collections/WindowsRuntimeReadOnlyDictionary{TKey, TValue}.cs +++ b/src/WinRT.Runtime2/Collections/WindowsRuntimeReadOnlyDictionary{TKey, TValue}.cs @@ -20,9 +20,6 @@ namespace WindowsRuntime; /// The interface type. /// The Windows.Foundation.Collections.IIterable<T> implementation type. /// The Windows.Foundation.Collections.IMapView<K, V> implementation type. -/// -/// This type should only be used as a base type by generated generic instantiations. -/// /// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, diff --git a/src/WinRT.Runtime2/Collections/WindowsRuntimeReadOnlyList{T}.cs b/src/WinRT.Runtime2/Collections/WindowsRuntimeReadOnlyList{T}.cs index edb0c44e1..987f6d67c 100644 --- a/src/WinRT.Runtime2/Collections/WindowsRuntimeReadOnlyList{T}.cs +++ b/src/WinRT.Runtime2/Collections/WindowsRuntimeReadOnlyList{T}.cs @@ -18,9 +18,6 @@ namespace WindowsRuntime; /// The Windows.Foundation.Collections.IIterable<T> interface type. /// The Windows.Foundation.Collections.IIterable<T> implementation type. /// The Windows.Foundation.Collections.IVectorView<T> implementation type. -/// -/// This type should only be used as a base type by generated generic instantiations. -/// /// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, diff --git a/src/WinRT.Runtime2/InteropServices/AsyncInfo/IAsyncActionWithProgressMethods.cs b/src/WinRT.Runtime2/InteropServices/AsyncInfo/IAsyncActionWithProgressMethods.cs new file mode 100644 index 000000000..428185760 --- /dev/null +++ b/src/WinRT.Runtime2/InteropServices/AsyncInfo/IAsyncActionWithProgressMethods.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace WindowsRuntime.InteropServices; + +/// +/// Methods for types. +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public static unsafe class IAsyncActionWithProgressMethods +{ + /// + /// The instance to use to invoke the native method. + [MethodImpl(MethodImplOptions.NoInlining)] + public static void GetResults(WindowsRuntimeObjectReference thisReference) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + + RestrictedErrorInfo.ThrowExceptionForHR(((IAsyncActionWithProgressVftbl*)*(void***)thisPtr)->GetResults(thisPtr)); + } +} diff --git a/src/WinRT.Runtime2/InteropServices/AsyncInfo/IAsyncActionWithProgressMethodsImpl{TProgress}.cs b/src/WinRT.Runtime2/InteropServices/AsyncInfo/IAsyncActionWithProgressMethodsImpl{TProgress}.cs new file mode 100644 index 000000000..17fb66d38 --- /dev/null +++ b/src/WinRT.Runtime2/InteropServices/AsyncInfo/IAsyncActionWithProgressMethodsImpl{TProgress}.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; +using Windows.Foundation; + +namespace WindowsRuntime.InteropServices; + +/// +/// An interface for implementations of types. +/// +/// The type of progress information. +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public interface IAsyncActionWithProgressMethodsImpl +{ + /// + /// Gets the callback method that receives progress notification. + /// + /// The instance to use to invoke the native method. + /// The callback. + /// + static abstract AsyncActionProgressHandler? Progress(WindowsRuntimeObjectReference thisReference); + + /// + /// Sets the callback method that receives progress notification. + /// + /// The instance to use to invoke the native method. + /// The callback. + /// + static abstract void Progress(WindowsRuntimeObjectReference thisReference, AsyncActionProgressHandler? handler); + + /// + /// Gets the delegate that is called when the action completes. + /// + /// The instance to use to invoke the native method. + /// The delegate. + /// + static abstract AsyncActionWithProgressCompletedHandler? Completed(WindowsRuntimeObjectReference thisReference); + + /// + /// Sets the delegate that is called when the action completes. + /// + /// The instance to use to invoke the native method. + /// The delegate. + /// + static abstract void Completed(WindowsRuntimeObjectReference thisReference, AsyncActionWithProgressCompletedHandler? handler); +} diff --git a/src/WinRT.Runtime2/InteropServices/AsyncInfo/IAsyncOperationMethodsImpl{TResult}.cs b/src/WinRT.Runtime2/InteropServices/AsyncInfo/IAsyncOperationMethodsImpl{TResult}.cs new file mode 100644 index 000000000..0a17b66e9 --- /dev/null +++ b/src/WinRT.Runtime2/InteropServices/AsyncInfo/IAsyncOperationMethodsImpl{TResult}.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; +using Windows.Foundation; + +namespace WindowsRuntime.InteropServices; + +/// +/// An interface for implementations of types. +/// +/// The result type. +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public interface IAsyncOperationMethodsImpl +{ + /// + /// Gets the delegate that is called when the action completes. + /// + /// The instance to use to invoke the native method. + /// The delegate. + /// + static abstract AsyncOperationCompletedHandler? Completed(WindowsRuntimeObjectReference thisReference); + + /// + /// Sets the delegate that is called when the action completes. + /// + /// The instance to use to invoke the native method. + /// The delegate. + /// + static abstract void Completed(WindowsRuntimeObjectReference thisReference, AsyncOperationCompletedHandler? handler); + + /// + /// Returns the results of the operation. + /// + /// The instance to use to invoke the native method. + /// The results of the operation. + /// + static abstract TResult GetResults(WindowsRuntimeObjectReference thisReference); +} diff --git a/src/WinRT.Runtime2/InteropServices/AsyncInfo/IAsyncOperationWithProgressMethodsImpl{TResult, TProgress}.cs b/src/WinRT.Runtime2/InteropServices/AsyncInfo/IAsyncOperationWithProgressMethodsImpl{TResult, TProgress}.cs new file mode 100644 index 000000000..cc5962f55 --- /dev/null +++ b/src/WinRT.Runtime2/InteropServices/AsyncInfo/IAsyncOperationWithProgressMethodsImpl{TResult, TProgress}.cs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; +using Windows.Foundation; + +namespace WindowsRuntime.InteropServices; + +/// +/// An interface for implementations of types. +/// +/// The result type. +/// The type of progress information. +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public interface IAsyncOperationWithProgressMethodsImpl +{ + /// + /// Gets the callback method that receives progress notification. + /// + /// The instance to use to invoke the native method. + /// The callback. + /// + static abstract AsyncOperationProgressHandler? Progress(WindowsRuntimeObjectReference thisReference); + + /// + /// Sets the callback method that receives progress notification. + /// + /// The instance to use to invoke the native method. + /// The callback. + /// + static abstract void Progress(WindowsRuntimeObjectReference thisReference, AsyncOperationProgressHandler? handler); + + /// + /// Gets the delegate that is called when the action completes. + /// + /// The instance to use to invoke the native method. + /// The delegate. + /// + static abstract AsyncOperationWithProgressCompletedHandler? Completed(WindowsRuntimeObjectReference thisReference); + + /// + /// Sets the delegate that is called when the action completes. + /// + /// The instance to use to invoke the native method. + /// The delegate. + /// + static abstract void Completed(WindowsRuntimeObjectReference thisReference, AsyncOperationWithProgressCompletedHandler? handler); + + /// + /// Returns the results of the operation. + /// + /// The instance to use to invoke the native method. + /// The results of the operation. + /// + static abstract TResult GetResults(WindowsRuntimeObjectReference thisReference); +} diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IDictionaryMethods.cs b/src/WinRT.Runtime2/InteropServices/Collections/IDictionaryMethods.cs index f8f51bf86..c91ae7435 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IDictionaryMethods.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IDictionaryMethods.cs @@ -11,9 +11,6 @@ namespace WindowsRuntime.InteropServices; /// /// Methods for implementations of types. /// -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IDictionaryMethods{TKey, TValue}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IDictionaryMethods{TKey, TValue}.cs index a60493481..1ff62a131 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IDictionaryMethods{TKey, TValue}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IDictionaryMethods{TKey, TValue}.cs @@ -15,9 +15,6 @@ namespace WindowsRuntime.InteropServices; /// /// The type of keys in the dictionary. /// The type of values in the dictionary. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IEnumeratorAdapter{T}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IEnumeratorAdapter{T}.cs index e16cb2ae0..63a812a74 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IEnumeratorAdapter{T}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IEnumeratorAdapter{T}.cs @@ -12,9 +12,6 @@ namespace WindowsRuntime.InteropServices; /// A stateful adapter for , to be exposed as Windows.Foundation.Collections.IIterator<T>. /// /// The type of objects to enumerate. -/// -/// This type should only be used by generated code. -/// /// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IIterableMethodsImpl{T}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IIterableMethodsImpl{T}.cs index cfec5e5e5..384974ac0 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IIterableMethodsImpl{T}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IIterableMethodsImpl{T}.cs @@ -11,9 +11,6 @@ namespace WindowsRuntime.InteropServices; /// An interface for implementations of Windows.Foundation.Collections.IIterable<T> types. /// /// The type of objects to enumerate. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IIteratorMethods.cs b/src/WinRT.Runtime2/InteropServices/Collections/IIteratorMethods.cs index 2a1897048..0486444f2 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IIteratorMethods.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IIteratorMethods.cs @@ -10,9 +10,6 @@ namespace WindowsRuntime.InteropServices; /// /// Methods for Windows.Foundation.Collections.IIterator<T> types. /// -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IIteratorMethodsImpl{T}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IIteratorMethodsImpl{T}.cs index 6f650e457..adb08dcef 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IIteratorMethodsImpl{T}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IIteratorMethodsImpl{T}.cs @@ -10,9 +10,6 @@ namespace WindowsRuntime.InteropServices; /// An interface for implementations of Windows.Foundation.Collections.IIterator<T> types. /// /// The type of objects to enumerate. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IListMethods.cs b/src/WinRT.Runtime2/InteropServices/Collections/IListMethods.cs index f5f5ff2fb..a8b70856c 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IListMethods.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IListMethods.cs @@ -11,9 +11,6 @@ namespace WindowsRuntime.InteropServices; /// /// Methods for types. /// -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IListMethods{T}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IListMethods{T}.cs index 455be1ca9..977499066 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IListMethods{T}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IListMethods{T}.cs @@ -13,9 +13,6 @@ namespace WindowsRuntime.InteropServices; /// Methods for types. /// /// The type of objects to enumerate. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IMapChangedEventArgsMethods.cs b/src/WinRT.Runtime2/InteropServices/Collections/IMapChangedEventArgsMethods.cs index 887d085f3..b4d81b694 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IMapChangedEventArgsMethods.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IMapChangedEventArgsMethods.cs @@ -11,9 +11,6 @@ namespace WindowsRuntime.InteropServices; /// /// Methods for Windows.Foundation.Collections.IMapChangedEventArgs<K> types. /// -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IMapChangedEventArgsMethodsImpl{K}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IMapChangedEventArgsMethodsImpl{K}.cs index dcbe18a7c..6ea3a5853 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IMapChangedEventArgsMethodsImpl{K}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IMapChangedEventArgsMethodsImpl{K}.cs @@ -10,9 +10,6 @@ namespace WindowsRuntime.InteropServices; /// An interface for implementations of Windows.Foundation.Collections.IMapChangedEventArgs<K> types. /// /// The type of keys in the map. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IMapMethods.cs b/src/WinRT.Runtime2/InteropServices/Collections/IMapMethods.cs index 18db330e8..6f8812192 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IMapMethods.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IMapMethods.cs @@ -12,9 +12,6 @@ namespace WindowsRuntime.InteropServices; /// /// Methods for Windows.Foundation.Collections.IMap<K, V> types. /// -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IMapMethodsImpl{K, V}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IMapMethodsImpl{K, V}.cs index 3c12c3f3d..c9af8fda6 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IMapMethodsImpl{K, V}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IMapMethodsImpl{K, V}.cs @@ -11,9 +11,6 @@ namespace WindowsRuntime.InteropServices; /// /// The type of keys in the map. /// The type of values in the map. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IMapViewMethods.cs b/src/WinRT.Runtime2/InteropServices/Collections/IMapViewMethods.cs index 828f5fb78..7de199d5b 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IMapViewMethods.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IMapViewMethods.cs @@ -9,9 +9,6 @@ namespace WindowsRuntime.InteropServices; /// /// Methods for Windows.Foundation.Collections.IMapView<K, V> types. /// -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IMapViewMethodsImpl{K, V}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IMapViewMethodsImpl{K, V}.cs index f79e2a070..bf3a1a084 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IMapViewMethodsImpl{K, V}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IMapViewMethodsImpl{K, V}.cs @@ -11,9 +11,6 @@ namespace WindowsRuntime.InteropServices; /// /// The type of keys in the map. /// The type of values in the map. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IObservableMapMethodsImpl{TKey, TValue}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IObservableMapMethodsImpl{TKey, TValue}.cs index f6263743d..dab1be7f7 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IObservableMapMethodsImpl{TKey, TValue}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IObservableMapMethodsImpl{TKey, TValue}.cs @@ -11,9 +11,6 @@ namespace WindowsRuntime.InteropServices; /// /// The type of keys in the observable map. /// The type of values in the observable map. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IObservableVectorMethodsImpl{T}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IObservableVectorMethodsImpl{T}.cs index 67e6a2f3e..0452486cd 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IObservableVectorMethodsImpl{T}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IObservableVectorMethodsImpl{T}.cs @@ -10,9 +10,6 @@ namespace WindowsRuntime.InteropServices; /// An interface for implementations of types. /// /// The type of elements in the observable vector. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyDictionaryMethods.cs b/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyDictionaryMethods.cs index 3d4cc9569..ec9786c99 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyDictionaryMethods.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyDictionaryMethods.cs @@ -11,9 +11,6 @@ namespace WindowsRuntime.InteropServices; /// /// Methods for types. /// -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyDictionaryMethods{TKey, TValue}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyDictionaryMethods{TKey, TValue}.cs index b2bdb29d4..525e0e5d3 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyDictionaryMethods{TKey, TValue}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyDictionaryMethods{TKey, TValue}.cs @@ -15,9 +15,6 @@ namespace WindowsRuntime.InteropServices; /// /// The type of keys in the read-only dictionary. /// The type of values in the read-only dictionary. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyListAdapter{T}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyListAdapter{T}.cs index 14fc92203..90ce976ac 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyListAdapter{T}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyListAdapter{T}.cs @@ -11,9 +11,6 @@ namespace WindowsRuntime.InteropServices; /// A stateless adapter for , to be exposed as Windows.Foundation.Collections.IVectorView<T>. /// /// The type of objects to enumerate. -/// -/// This type should only be used by generated code. -/// /// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyListMethods.cs b/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyListMethods.cs index 6af4c034e..0e87f2f93 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyListMethods.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyListMethods.cs @@ -10,9 +10,6 @@ namespace WindowsRuntime.InteropServices; /// /// Methods for types. /// -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyListMethods{T}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyListMethods{T}.cs index d5b88c0c9..25cb72a62 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyListMethods{T}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyListMethods{T}.cs @@ -12,9 +12,6 @@ namespace WindowsRuntime.InteropServices; /// Methods for types. /// /// The type of objects to enumerate. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IVectorMethods.cs b/src/WinRT.Runtime2/InteropServices/Collections/IVectorMethods.cs index b79eac63b..cfde1d78d 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IVectorMethods.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IVectorMethods.cs @@ -10,9 +10,6 @@ namespace WindowsRuntime.InteropServices; /// /// Methods for Windows.Foundation.Collections.IVector<T> types. /// -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IVectorMethodsImpl{T}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IVectorMethodsImpl{T}.cs index 1c2a9995d..907b5bc1b 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IVectorMethodsImpl{T}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IVectorMethodsImpl{T}.cs @@ -10,9 +10,6 @@ namespace WindowsRuntime.InteropServices; /// An interface for implementations of Windows.Foundation.Collections.IVector<T> types. /// /// The type of objects to enumerate. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IVectorViewMethods.cs b/src/WinRT.Runtime2/InteropServices/Collections/IVectorViewMethods.cs index 995dfb3c6..b1dcbf5ed 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IVectorViewMethods.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IVectorViewMethods.cs @@ -10,9 +10,6 @@ namespace WindowsRuntime.InteropServices; /// /// Methods for Windows.Foundation.Collections.IVectorView<T> types. /// -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IVectorViewMethodsImpl{T}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IVectorViewMethodsImpl{T}.cs index 60debccd0..78d329d3e 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IVectorViewMethodsImpl{T}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IVectorViewMethodsImpl{T}.cs @@ -10,9 +10,6 @@ namespace WindowsRuntime.InteropServices; /// An interface for implementations of Windows.Foundation.Collections.IVectorView<T> types. /// /// The type of objects to enumerate. -/// -/// This type should only be used by generated code. -/// [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] diff --git a/src/WinRT.Runtime2/InteropServices/Vtables/IAsyncActionWithProgressVftbl.cs b/src/WinRT.Runtime2/InteropServices/Vtables/IAsyncActionWithProgressVftbl.cs new file mode 100644 index 000000000..ee28d66b2 --- /dev/null +++ b/src/WinRT.Runtime2/InteropServices/Vtables/IAsyncActionWithProgressVftbl.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using Windows.Foundation; + +namespace WindowsRuntime.InteropServices; + +/// +/// Binding type for the interface vtable. +/// +/// +[StructLayout(LayoutKind.Sequential)] +internal unsafe struct IAsyncActionWithProgressVftbl +{ + public delegate* unmanaged[MemberFunction] QueryInterface; + public delegate* unmanaged[MemberFunction] AddRef; + public delegate* unmanaged[MemberFunction] Release; + public delegate* unmanaged[MemberFunction] GetIids; + public delegate* unmanaged[MemberFunction] GetRuntimeClassName; + public delegate* unmanaged[MemberFunction] GetTrustLevel; + public delegate* unmanaged[MemberFunction] get_Progress; + public delegate* unmanaged[MemberFunction] set_Progress; + public delegate* unmanaged[MemberFunction] get_Completed; + public delegate* unmanaged[MemberFunction] set_Completed; + public delegate* unmanaged[MemberFunction] GetResults; +} diff --git a/src/WinRT.Runtime2/Windows.Foundation/IAsyncOperationWithProgress{TResult, TProgress}.cs b/src/WinRT.Runtime2/Windows.Foundation/IAsyncOperationWithProgress{TResult, TProgress}.cs index 820d49a0c..eacffb755 100644 --- a/src/WinRT.Runtime2/Windows.Foundation/IAsyncOperationWithProgress{TResult, TProgress}.cs +++ b/src/WinRT.Runtime2/Windows.Foundation/IAsyncOperationWithProgress{TResult, TProgress}.cs @@ -26,7 +26,7 @@ public interface IAsyncOperationWithProgress : IAsyncInfo /// /// Gets or sets the method that handles progress notifications. /// - AsyncOperationProgressHandler Progress { get; set; } + AsyncOperationProgressHandler? Progress { get; set; } /// /// Gets or sets the delegate that is called when the operation completes. @@ -41,7 +41,7 @@ public interface IAsyncOperationWithProgress : IAsyncInfo /// before the property setter has returned; possibly even from the same thread. /// /// - AsyncOperationWithProgressCompletedHandler Completed { get; set; } + AsyncOperationWithProgressCompletedHandler? Completed { get; set; } /// /// Returns the results of the operation.