From 7de517c993b63147a89fff5e4fcf4cda37e76706 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Tue, 16 May 2023 15:13:01 -0700 Subject: [PATCH 1/5] wip --- .../ComInterfaceGenerator.cs | 17 +- .../MarshallingInfoParser.cs | 2 +- .../ref/System.Runtime.InteropServices.cs | 192 +++++++++--------- .../GeneratedComInterfaceAttribute.cs | 2 + .../StringMarshallingTests.cs | 15 ++ .../StringMarshalling.cs | 112 ++++++++++ .../ICustomStringMarshallingUtf16.cs | 20 ++ .../ComInterfaces/IUTF16Marshalling.cs | 20 ++ .../ComInterfaces/IUTF8Marshalling.cs | 20 ++ 9 files changed, 302 insertions(+), 98 deletions(-) create mode 100644 src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/StringMarshallingTests.cs create mode 100644 src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/ComInterfaceGenerator/StringMarshalling.cs create mode 100644 src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/ICustomStringMarshallingUtf16.cs create mode 100644 src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IUTF16Marshalling.cs create mode 100644 src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IUTF8Marshalling.cs diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs index 85f01c4f9e0da..01a1a930ae5ee 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs @@ -282,7 +282,7 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M AttributeData? generatedComAttribute = null; foreach (var attr in symbol.ContainingType.GetAttributes()) { - if (generatedComAttribute is not null && attr.AttributeClass?.ToDisplayString() == TypeNames.GeneratedComInterfaceAttribute) + if (generatedComAttribute is null && attr.AttributeClass?.ToDisplayString() == TypeNames.GeneratedComInterfaceAttribute) { generatedComAttribute = attr; } @@ -296,8 +296,21 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M generatorDiagnostics.ReportConfigurationNotSupported(lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); } + var args = generatedComAttribute?.NamedArguments.ToImmutableDictionary(); + var iacd = new InteropAttributeCompilationData(); + if (args is not null) + iacd = iacd.WithValuesFromNamedArguments(args); // Create the stub. - var signatureContext = SignatureContext.Create(symbol, DefaultMarshallingInfoParser.Create(environment, generatorDiagnostics, symbol, new InteropAttributeCompilationData(), generatedComAttribute), environment, typeof(VtableIndexStubGenerator).Assembly); + var signatureContext = SignatureContext.Create( + symbol, + DefaultMarshallingInfoParser.Create( + environment, + generatorDiagnostics, + symbol, + iacd, + generatedComAttribute), + environment, + typeof(VtableIndexStubGenerator).Assembly); if (!symbol.MethodImplementationFlags.HasFlag(MethodImplAttributes.PreserveSig)) { diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParser.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParser.cs index 410166893a514..7629c68e9713c 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParser.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParser.cs @@ -73,7 +73,7 @@ public interface IMarshallingInfoAttributeParser } /// - /// A provider of marshalling info based only on the managed type any any previously parsed use-site attribute information + /// A provider of marshalling info based only on the managed type and any previously parsed use-site attribute information /// public interface ITypeBasedMarshallingInfoProvider { diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index 5f82435829d89..60ce5dc6782f3 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -8,13 +8,13 @@ namespace System.Runtime.CompilerServices { [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] - [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter, Inherited = false)] public sealed partial class IDispatchConstantAttribute : System.Runtime.CompilerServices.CustomConstantAttribute { public IDispatchConstantAttribute() { } public override object Value { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter, Inherited = false)] public sealed partial class IUnknownConstantAttribute : System.Runtime.CompilerServices.CustomConstantAttribute { public IUnknownConstantAttribute() { } @@ -23,13 +23,13 @@ public IUnknownConstantAttribute() { } } namespace System.Runtime.InteropServices { - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Interface, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Interface, Inherited = false)] public sealed partial class AutomationProxyAttribute : System.Attribute { public AutomationProxyAttribute(bool val) { } public bool Value { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue, Inherited = false)] public sealed partial class ComAliasNameAttribute : System.Attribute { public ComAliasNameAttribute(string alias) { } @@ -58,7 +58,7 @@ public override void AddEventHandler(object target, System.Delegate handler) { } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] public override void RemoveEventHandler(object target, System.Delegate handler) { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited = false)] public sealed partial class ComCompatibleVersionAttribute : System.Attribute { public ComCompatibleVersionAttribute(int major, int minor, int build, int revision) { } @@ -67,17 +67,17 @@ public ComCompatibleVersionAttribute(int major, int minor, int build, int revisi public int MinorVersion { get { throw null; } } public int RevisionNumber { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.All, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.All, Inherited = false)] public sealed partial class ComConversionLossAttribute : System.Attribute { public ComConversionLossAttribute() { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false)] public sealed partial class ComRegisterFunctionAttribute : System.Attribute { public ComRegisterFunctionAttribute() { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false)] public sealed partial class ComUnregisterFunctionAttribute : System.Attribute { public ComUnregisterFunctionAttribute() { } @@ -93,20 +93,20 @@ public HandleCollector(string? name, int initialThreshold, int maximumThreshold) public void Add() { } public void Remove() { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited = false)] public sealed partial class ImportedFromTypeLibAttribute : System.Attribute { public ImportedFromTypeLibAttribute(string tlbFile) { } public string Value { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false, AllowMultiple=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false, AllowMultiple = false)] public sealed partial class ManagedToNativeComInteropStubAttribute : System.Attribute { public ManagedToNativeComInteropStubAttribute(System.Type classType, string methodName) { } public System.Type ClassType { get { throw null; } } public string MethodName { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited=false, AllowMultiple=true)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited = false, AllowMultiple = true)] public sealed partial class PrimaryInteropAssemblyAttribute : System.Attribute { public PrimaryInteropAssemblyAttribute(int major, int minor) { } @@ -125,7 +125,7 @@ public static partial class RuntimeEnvironment public static object GetRuntimeInterfaceAsObject(System.Guid clsid, System.Guid riid) { throw null; } public static string GetSystemVersion() { throw null; } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false)] public sealed partial class TypeLibFuncAttribute : System.Attribute { public TypeLibFuncAttribute(short flags) { } @@ -149,13 +149,13 @@ public enum TypeLibFuncFlags FReplaceable = 2048, FImmediateBind = 4096, } - [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited = false)] public sealed partial class TypeLibImportClassAttribute : System.Attribute { public TypeLibImportClassAttribute(System.Type importClass) { } public string Value { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited = false)] public sealed partial class TypeLibTypeAttribute : System.Attribute { public TypeLibTypeAttribute(short flags) { } @@ -180,7 +180,7 @@ public enum TypeLibTypeFlags FDispatchable = 4096, FReverseBind = 8192, } - [System.AttributeUsageAttribute(System.AttributeTargets.Field, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Field, Inherited = false)] public sealed partial class TypeLibVarAttribute : System.Attribute { public TypeLibVarAttribute(short flags) { } @@ -204,7 +204,7 @@ public enum TypeLibVarFlags FReplaceable = 2048, FImmediateBind = 4096, } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited = false)] public sealed partial class TypeLibVersionAttribute : System.Attribute { public TypeLibVersionAttribute(int major, int minor) { } @@ -370,6 +370,8 @@ public GeneratedComClassAttribute() { } public partial class GeneratedComInterfaceAttribute : System.Attribute { public GeneratedComInterfaceAttribute() { } + public StringMarshalling StringMarshalling { get{ throw null; } set { } } + public Type StringMarshallingCustomType { get{ throw null; } set { } } } [System.CLSCompliantAttribute(false)] public partial interface IComExposedClass @@ -547,7 +549,7 @@ public void Write(long position, ref T structure) where T : struct { } namespace System.Runtime.InteropServices { [System.ObsoleteAttribute("Code Access Security is not supported or honored by the runtime.", DiagnosticId = "SYSLIB0003", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] - [System.AttributeUsageAttribute(System.AttributeTargets.Method, AllowMultiple=false, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] public sealed partial class AllowReversePInvokeCallsAttribute : System.Attribute { public AllowReversePInvokeCallsAttribute() { } @@ -565,7 +567,7 @@ public AllowReversePInvokeCallsAttribute() { } public static bool operator ==(System.Runtime.InteropServices.ArrayWithOffset a, System.Runtime.InteropServices.ArrayWithOffset b) { throw null; } public static bool operator !=(System.Runtime.InteropServices.ArrayWithOffset a, System.Runtime.InteropServices.ArrayWithOffset b) { throw null; } } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited = false)] public sealed partial class BestFitMappingAttribute : System.Attribute { public bool ThrowOnUnmappableChar; @@ -587,7 +589,7 @@ public enum CallingConvention ThisCall = 4, FastCall = 5, } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class, Inherited = false)] public sealed partial class ClassInterfaceAttribute : System.Attribute { public ClassInterfaceAttribute(short classInterfaceType) { } @@ -612,7 +614,7 @@ public enum ClassInterfaceType public override int GetHashCode() { throw null; } public override string ToString() { throw null; } } - [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited = false)] public sealed partial class CoClassAttribute : System.Attribute { public CoClassAttribute(System.Type coClass) { } @@ -625,13 +627,13 @@ public static partial class CollectionsMarshal public static ref TValue? GetValueRefOrAddDefault(System.Collections.Generic.Dictionary dictionary, TKey key, out bool exists) where TKey : notnull { throw null; } public static void SetCount(System.Collections.Generic.List list, int count) { throw null; } } - [System.AttributeUsageAttribute(System.AttributeTargets.Class, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Class, Inherited = false)] public sealed partial class ComDefaultInterfaceAttribute : System.Attribute { public ComDefaultInterfaceAttribute(System.Type defaultInterface) { } public System.Type Value { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited = false)] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public sealed partial class ComEventInterfaceAttribute : System.Attribute { @@ -659,7 +661,7 @@ public COMException(string? message, System.Exception? inner) { } public COMException(string? message, int errorCode) { } public override string ToString() { throw null; } } - [System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Interface, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Interface, Inherited = false)] public sealed partial class ComImportAttribute : System.Attribute { public ComImportAttribute() { } @@ -677,7 +679,7 @@ public enum ComMemberType PropGet = 1, PropSet = 2, } - [System.AttributeUsageAttribute(System.AttributeTargets.Class, Inherited=true)] + [System.AttributeUsageAttribute(System.AttributeTargets.Class, Inherited = true)] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public sealed partial class ComSourceInterfacesAttribute : System.Attribute { @@ -768,13 +770,13 @@ public enum CustomQueryInterfaceResult NotHandled = 1, Failed = 2, } - [System.AttributeUsageAttribute(System.AttributeTargets.Module, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Module, Inherited = false)] public sealed partial class DefaultCharSetAttribute : System.Attribute { public DefaultCharSetAttribute(System.Runtime.InteropServices.CharSet charSet) { } public System.Runtime.InteropServices.CharSet CharSet { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Method, AllowMultiple=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Method, AllowMultiple = false)] public sealed partial class DefaultDllImportSearchPathsAttribute : System.Attribute { public DefaultDllImportSearchPathsAttribute(System.Runtime.InteropServices.DllImportSearchPath paths) { } @@ -793,13 +795,13 @@ public sealed partial class DispatchWrapper public DispatchWrapper(object? obj) { } public object? WrappedObject { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Method | System.AttributeTargets.Property, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Method | System.AttributeTargets.Property, Inherited = false)] public sealed partial class DispIdAttribute : System.Attribute { public DispIdAttribute(int dispId) { } public int Value { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false)] public sealed partial class DllImportAttribute : System.Attribute { public bool BestFitMapping; @@ -825,7 +827,7 @@ public enum DllImportSearchPath System32 = 2048, SafeDirectories = 4096, } - [System.AttributeUsageAttribute(System.AttributeTargets.Interface, AllowMultiple=false, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] public sealed class DynamicInterfaceCastableImplementationAttribute : Attribute { public DynamicInterfaceCastableImplementationAttribute() { } @@ -838,7 +840,7 @@ public ErrorWrapper(int errorCode) { } public ErrorWrapper(object errorCode) { } public int ErrorCode { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited = false)] public sealed partial class GuidAttribute : System.Attribute { public GuidAttribute(string guid) { } @@ -851,7 +853,7 @@ public readonly partial struct HandleRef public HandleRef(object? wrapper, System.IntPtr handle) { throw null; } public System.IntPtr Handle { get { throw null; } } public object? Wrapper { get { throw null; } } - public static explicit operator System.IntPtr (System.Runtime.InteropServices.HandleRef value) { throw null; } + public static explicit operator System.IntPtr(System.Runtime.InteropServices.HandleRef value) { throw null; } public static System.IntPtr ToIntPtr(System.Runtime.InteropServices.HandleRef value) { throw null; } } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] @@ -881,7 +883,7 @@ public partial interface IDynamicInterfaceCastable bool IsInterfaceImplemented(System.RuntimeTypeHandle interfaceType, bool throwIfNotImplemented); System.RuntimeTypeHandle GetInterfaceImplementation(System.RuntimeTypeHandle interfaceType); } - [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited = false)] public sealed partial class InterfaceTypeAttribute : System.Attribute { public InterfaceTypeAttribute(short interfaceType) { } @@ -906,19 +908,19 @@ protected InvalidOleVariantTypeException(System.Runtime.Serialization.Serializat public InvalidOleVariantTypeException(string? message) { } public InvalidOleVariantTypeException(string? message, System.Exception? inner) { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false)] public sealed partial class LCIDConversionAttribute : System.Attribute { public LCIDConversionAttribute(int lcid) { } public int Value { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, AllowMultiple = false, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] public sealed partial class LibraryImportAttribute : System.Attribute { public LibraryImportAttribute(string libraryName) { } public string LibraryName { get { throw null; } } public string? EntryPoint { get { throw null; } set { } } - public bool SetLastError { get { throw null; } set { }} + public bool SetLastError { get { throw null; } set { } } public System.Runtime.InteropServices.StringMarshalling StringMarshalling { get { throw null; } set { } } public System.Type? StringMarshallingCustomType { get { throw null; } set { } } } @@ -1066,8 +1068,8 @@ public static void PrelinkAll(System.Type c) { } public static void PtrToStructure(System.IntPtr ptr, object structure) { } [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public static object? PtrToStructure(System.IntPtr ptr, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors| System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type structureType) { throw null; } - public static T? PtrToStructure<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]T>(System.IntPtr ptr) { throw null; } + public static object? PtrToStructure(System.IntPtr ptr, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type structureType) { throw null; } + public static T? PtrToStructure<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] T>(System.IntPtr ptr) { throw null; } public static void PtrToStructure(System.IntPtr ptr, [System.Diagnostics.CodeAnalysis.DisallowNullAttribute] T structure) { } public static int QueryInterface(System.IntPtr pUnk, ref System.Guid iid, out System.IntPtr ppv) { throw null; } public static byte ReadByte(System.IntPtr ptr) { throw null; } @@ -1182,7 +1184,7 @@ public static void ZeroFreeCoTaskMemUTF8(System.IntPtr s) { } public static void ZeroFreeGlobalAllocAnsi(System.IntPtr s) { } public static void ZeroFreeGlobalAllocUnicode(System.IntPtr s) { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.ReturnValue, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.ReturnValue, Inherited = false)] public sealed partial class MarshalAsAttribute : System.Attribute { public System.Runtime.InteropServices.UnmanagedType ArraySubType; @@ -1261,9 +1263,9 @@ public static void Free(void* ptr) { } public static System.Runtime.InteropServices.NFloat Pi { get { throw null; } } public static System.Runtime.InteropServices.NFloat PositiveInfinity { get { throw null; } } public static int Size { get { throw null; } } - static System.Runtime.InteropServices.NFloat System.Numerics.IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + static System.Runtime.InteropServices.NFloat System.Numerics.IAdditiveIdentity.AdditiveIdentity { get { throw null; } } static System.Runtime.InteropServices.NFloat System.Numerics.IBinaryNumber.AllBitsSet { get { throw null; } } - static System.Runtime.InteropServices.NFloat System.Numerics.IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + static System.Runtime.InteropServices.NFloat System.Numerics.IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } static System.Runtime.InteropServices.NFloat System.Numerics.INumberBase.One { get { throw null; } } static int System.Numerics.INumberBase.Radix { get { throw null; } } static System.Runtime.InteropServices.NFloat System.Numerics.INumberBase.Zero { get { throw null; } } @@ -1341,76 +1343,76 @@ public static void Free(void* ptr) { } public static System.Runtime.InteropServices.NFloat MinMagnitudeNumber(System.Runtime.InteropServices.NFloat x, System.Runtime.InteropServices.NFloat y) { throw null; } public static System.Runtime.InteropServices.NFloat MinNumber(System.Runtime.InteropServices.NFloat x, System.Runtime.InteropServices.NFloat y) { throw null; } public static System.Runtime.InteropServices.NFloat operator +(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } - public static explicit operator checked byte (System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator checked char (System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator checked short (System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator checked int (System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator checked long (System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator checked System.Int128 (System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator checked nint (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked byte(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked char(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked short(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked int(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked long(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked System.Int128(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked nint(System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator checked sbyte (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked sbyte(System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator checked ushort (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked ushort(System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator checked uint (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked uint(System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator checked ulong (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked ulong(System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator checked System.UInt128 (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked System.UInt128(System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator checked nuint (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked nuint(System.Runtime.InteropServices.NFloat value) { throw null; } public static System.Runtime.InteropServices.NFloat operator --(System.Runtime.InteropServices.NFloat value) { throw null; } public static System.Runtime.InteropServices.NFloat operator /(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } public static bool operator ==(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } - public static explicit operator System.Runtime.InteropServices.NFloat (decimal value) { throw null; } - public static explicit operator System.Runtime.InteropServices.NFloat (double value) { throw null; } - public static explicit operator System.Runtime.InteropServices.NFloat (System.Int128 value) { throw null; } - public static explicit operator byte (System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator char (System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator decimal (System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator System.Half (System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator System.Int128 (System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator short (System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator int (System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator long (System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator nint (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator System.Runtime.InteropServices.NFloat(decimal value) { throw null; } + public static explicit operator System.Runtime.InteropServices.NFloat(double value) { throw null; } + public static explicit operator System.Runtime.InteropServices.NFloat(System.Int128 value) { throw null; } + public static explicit operator byte(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator char(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator decimal(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator System.Half(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator System.Int128(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator short(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator int(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator long(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator nint(System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator sbyte (System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator float (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator sbyte(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator float(System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator System.UInt128 (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator System.UInt128(System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator ushort (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator ushort(System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator uint (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator uint(System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator ulong (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator ulong(System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator nuint (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator nuint(System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator System.Runtime.InteropServices.NFloat (System.UInt128 value) { throw null; } + public static explicit operator System.Runtime.InteropServices.NFloat(System.UInt128 value) { throw null; } public static bool operator >(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } public static bool operator >=(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat (byte value) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat (char value) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat (short value) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat (int value) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat (long value) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat (nint value) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat (System.Half value) { throw null; } - public static implicit operator double (System.Runtime.InteropServices.NFloat value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat(byte value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat(char value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat(short value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat(int value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat(long value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat(nint value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat(System.Half value) { throw null; } + public static implicit operator double(System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Runtime.InteropServices.NFloat (sbyte value) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat (float value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat(sbyte value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat(float value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Runtime.InteropServices.NFloat (ushort value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat(ushort value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Runtime.InteropServices.NFloat (uint value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat(uint value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Runtime.InteropServices.NFloat (ulong value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat(ulong value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Runtime.InteropServices.NFloat (nuint value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat(nuint value) { throw null; } public static System.Runtime.InteropServices.NFloat operator ++(System.Runtime.InteropServices.NFloat value) { throw null; } public static bool operator !=(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } public static bool operator <(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } @@ -1488,7 +1490,7 @@ public static void Free(void* ptr) { } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out System.Runtime.InteropServices.NFloat result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.Runtime.InteropServices.NFloat result) { throw null; } } - [System.AttributeUsageAttribute(System.AttributeTargets.Parameter, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Parameter, Inherited = false)] public sealed partial class OptionalAttribute : System.Attribute { public OptionalAttribute() { } @@ -1529,12 +1531,12 @@ internal PosixSignalRegistration() { } public void Dispose() { } ~PosixSignalRegistration() { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false)] public sealed partial class PreserveSigAttribute : System.Attribute { public PreserveSigAttribute() { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Class, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Class, Inherited = false)] public sealed partial class ProgIdAttribute : System.Attribute { public ProgIdAttribute(string progId) { } @@ -1578,7 +1580,7 @@ public enum StringMarshalling Utf8 = 1, Utf16 = 2, } - [System.AttributeUsageAttribute(System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, AllowMultiple=false, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, AllowMultiple = false, Inherited = false)] public sealed partial class TypeIdentifierAttribute : System.Attribute { public TypeIdentifierAttribute() { } @@ -1605,7 +1607,7 @@ public UnmanagedCallersOnlyAttribute() { } public System.Type[]? CallConvs; public string? EntryPoint; } - [System.AttributeUsageAttribute(System.AttributeTargets.Delegate, AllowMultiple=false, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] public sealed partial class UnmanagedFunctionPointerAttribute : System.Attribute { public bool BestFitMapping; @@ -2322,7 +2324,7 @@ public ref struct ManagedToUnmanagedIn { public static int BufferSize { get { throw null; } } public void FromManaged(string? managed, System.Span buffer) { throw null; } - public byte* ToUnmanaged() { throw null; } + public byte* ToUnmanaged() { throw null; } public void Free() { throw null; } } } @@ -2377,7 +2379,7 @@ public ref struct ManagedToUnmanagedIn { public static int BufferSize { get { throw null; } } public void FromManaged(string? managed, System.Span buffer) { throw null; } - public ushort* ToUnmanaged() { throw null; } + public ushort* ToUnmanaged() { throw null; } public void Free() { throw null; } } } @@ -2443,7 +2445,7 @@ public ref struct ManagedToUnmanagedIn { public static int BufferSize { get { throw null; } } public void FromManaged(string? managed, System.Span buffer) { throw null; } - public byte* ToUnmanaged() { throw null; } + public byte* ToUnmanaged() { throw null; } public void Free() { throw null; } } } diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/Marshalling/GeneratedComInterfaceAttribute.cs b/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/Marshalling/GeneratedComInterfaceAttribute.cs index 7d81e174d9666..d8a18b41182b4 100644 --- a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/Marshalling/GeneratedComInterfaceAttribute.cs +++ b/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/Marshalling/GeneratedComInterfaceAttribute.cs @@ -6,5 +6,7 @@ namespace System.Runtime.InteropServices.Marshalling [AttributeUsage(AttributeTargets.Interface)] public class GeneratedComInterfaceAttribute : Attribute { + public StringMarshalling StringMarshalling { get; set; } + public Type? StringMarshallingCustomType { get; set; } } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/StringMarshallingTests.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/StringMarshallingTests.cs new file mode 100644 index 0000000000000..9d64ee3079a5e --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/StringMarshallingTests.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComInterfaceGenerator.Tests +{ + internal class StringMarshallingTests + { + } +} diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/ComInterfaceGenerator/StringMarshalling.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/ComInterfaceGenerator/StringMarshalling.cs new file mode 100644 index 0000000000000..316ab112d876b --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/ComInterfaceGenerator/StringMarshalling.cs @@ -0,0 +1,112 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using SharedTypes.ComInterfaces; +using static System.Runtime.InteropServices.ComWrappers; + +namespace NativeExports.ComInterfaceGenerator +{ + public unsafe class StringMarshalling { + // Call from another assembly to get a ptr to make an RCW + [UnmanagedCallersOnly(EntryPoint = "new_get_and_set_int")] + public static void* CreateComObject() + { + MyComWrapper cw = new(); + var myObject = new ImplementingObject(); + nint ptr = cw.GetOrCreateComInterfaceForObject(myObject, CreateComInterfaceFlags.None); + + return (void*)ptr; + } + + class MyComWrapper : ComWrappers + { + static void* _s_comInterface1VTable = null; + static void* s_comInterface1VTable + { + get + { + if (MyComWrapper._s_comInterface1VTable != null) + return _s_comInterface1VTable; + void** vtable = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(GetAndSetInt), sizeof(void*) * 5); + GetIUnknownImpl(out var fpQueryInterface, out var fpAddReference, out var fpRelease); + vtable[0] = (void*)fpQueryInterface; + vtable[1] = (void*)fpAddReference; + vtable[2] = (void*)fpRelease; + vtable[3] = (delegate* unmanaged)&ImplementingObject.ABI.GetInt; + vtable[4] = (delegate* unmanaged)&ImplementingObject.ABI.SetInt; + _s_comInterface1VTable = vtable; + return _s_comInterface1VTable; + } + } + protected override ComInterfaceEntry* ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count) + { + if (obj is ImplementingObject) + { + ComInterfaceEntry* comInterfaceEntry = (ComInterfaceEntry*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ImplementingObject), sizeof(ComInterfaceEntry)); + comInterfaceEntry->IID = new Guid(IGetAndSetInt._guid); + comInterfaceEntry->Vtable = (nint)s_comInterface1VTable; + count = 1; + return comInterfaceEntry; + } + count = 0; + return null; + } + + protected override object? CreateObject(nint externalComObject, CreateObjectFlags flags) => throw new NotImplementedException(); + protected override void ReleaseObjects(IEnumerable objects) => throw new NotImplementedException(); + } + + class ImplementingObject : IGetAndSetInt + { + int _data = 0; + + int IGetAndSetInt.GetInt() + { + return _data; + } + void IGetAndSetInt.SetInt(int x) + { + _data = x; + } + + // Provides function pointers in the COM format to use in COM VTables + public static class ABI + { + + [UnmanagedCallersOnly] + public static int GetInt(void* @this, int* value) + { + try + { + *value = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)@this).GetInt(); + return 0; + } + catch (Exception e) + { + return e.HResult; + } + } + + [UnmanagedCallersOnly] + public static int SetInt(void* @this, int newValue) + { + try + { + ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)@this).SetInt(newValue); + return 0; + } + catch (Exception e) + { + return e.HResult; + } + } + } + } + } +} diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/ICustomStringMarshallingUtf16.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/ICustomStringMarshallingUtf16.cs new file mode 100644 index 0000000000000..d792b62d6d5a9 --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/ICustomStringMarshallingUtf16.cs @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.Marshalling; + +namespace SharedTypes.ComInterfaces +{ + [Guid(_guid)] + [GeneratedComInterface(StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(Utf16StringMarshaller))] + internal partial interface ICustomStringMarshallingUtf16 + { + public string GetString(); + + public void SetString(string value); + + public const string _guid = "E11D5F3E-DD57-41A6-A59E-7D110551A760"; + } +} diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IUTF16Marshalling.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IUTF16Marshalling.cs new file mode 100644 index 0000000000000..2ef5534aa6b23 --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IUTF16Marshalling.cs @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.Marshalling; + +namespace SharedTypes.ComInterfaces +{ + [Guid(_guid)] + [GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)] + internal partial interface IUTF16Marshalling + { + public string GetString(); + + public void SetString(string value); + + public const string _guid = "E11D5F3E-DD57-41A6-A59E-7D110551A760"; + } +} diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IUTF8Marshalling.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IUTF8Marshalling.cs new file mode 100644 index 0000000000000..2689425abd506 --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IUTF8Marshalling.cs @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.Marshalling; + +namespace SharedTypes.ComInterfaces +{ + [Guid(_guid)] + [GeneratedComInterface(StringMarshalling = StringMarshalling.Utf8)] + internal partial interface IUTF8Marshalling + { + public string GetString(); + + public void SetString(string value); + + public const string _guid = "E11D5F3E-DD57-41A6-A59E-7D110551A760"; + } +} From e8f40a8519b19e4fc816c1681ea0ad9790f04645 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Wed, 17 May 2023 11:01:02 -0700 Subject: [PATCH 2/5] Add tests --- .../StringMarshallingTests.cs | 98 +++++- .../StringMarshalling.cs | 283 ++++++++++++------ 2 files changed, 283 insertions(+), 98 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/StringMarshallingTests.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/StringMarshallingTests.cs index 9d64ee3079a5e..175296047f845 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/StringMarshallingTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/StringMarshallingTests.cs @@ -4,12 +4,108 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.Marshalling; using System.Text; +using System.Threading; using System.Threading.Tasks; +using SharedTypes.ComInterfaces; +using Xunit; namespace ComInterfaceGenerator.Tests { - internal class StringMarshallingTests + public unsafe partial class StringMarshallingTests { + [LibraryImport(NativeExportsNE.NativeExportsNE_Binary, EntryPoint = "new_utf8_marshalling")] + public static partial void* NewIUtf8Marshalling(); + + [LibraryImport(NativeExportsNE.NativeExportsNE_Binary, EntryPoint = "new_utf16_marshalling")] + public static partial void* NewIUtf16Marshalling(); + + [GeneratedComClass] + internal partial class Utf8MarshalledClass : IUTF8Marshalling + { + string _data = "Hello, World!"; + + public string GetString() => _data; + public void SetString(string value) => _data = value; + } + + [GeneratedComClass] + internal partial class Utf16MarshalledClass : IUTF16Marshalling + { + string _data = "Hello, World!"; + + public string GetString() => _data; + public void SetString(string value) => _data = value; + } + + [GeneratedComClass] + internal partial class CustomUtf16MarshalledClass : ICustomStringMarshallingUtf16 + { + string _data = "Hello, World!"; + + public string GetString() => _data; + public void SetString(string value) => _data = value; + } + + [Fact] + public void ValidateStringMarshallingRCW() + { + var cw = new StrategyBasedComWrappers(); + var utf8 = NewIUtf8Marshalling(); + IUTF8Marshalling obj8 = (IUTF8Marshalling)cw.GetOrCreateObjectForComInstance((nint)utf8, CreateObjectFlags.None); + string value = obj8.GetString(); + Assert.Equal("Hello, World!", value); + obj8.SetString("TestString"); + value = obj8.GetString(); + Assert.Equal("TestString", value); + + var utf16 = NewIUtf16Marshalling(); + IUTF16Marshalling obj16 = (IUTF16Marshalling)cw.GetOrCreateObjectForComInstance((nint)utf16, CreateObjectFlags.None); + Assert.Equal("Hello, World!", obj16.GetString()); + obj16.SetString("TestString"); + Assert.Equal("TestString", obj16.GetString()); + + var utf16custom = NewIUtf16Marshalling(); + ICustomStringMarshallingUtf16 objCustom = (ICustomStringMarshallingUtf16)cw.GetOrCreateObjectForComInstance((nint)utf16custom, CreateObjectFlags.None); + Assert.Equal("Hello, World!", objCustom.GetString()); + objCustom.SetString("TestString"); + Assert.Equal("TestString", objCustom.GetString()); + } + + [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/85795", TargetFrameworkMonikers.Any)] + public void RcwToCcw() + { + var cw = new StrategyBasedComWrappers(); + + var utf8 = new Utf8MarshalledClass(); + var utf8ComInstance = cw.GetOrCreateComInterfaceForObject(utf8, CreateComInterfaceFlags.None); + var utf8ComObject = (IUTF8Marshalling)cw.GetOrCreateObjectForComInstance(utf8ComInstance, CreateObjectFlags.None); + Assert.Equal(utf8.GetString(), utf8ComObject.GetString()); + utf8.SetString("Set from CLR object"); + Assert.Equal(utf8.GetString(), utf8ComObject.GetString()); + utf8ComObject.SetString("Set from COM object"); + Assert.Equal(utf8.GetString(), utf8ComObject.GetString()); + + var utf16 = new Utf16MarshalledClass(); + var utf16ComInstance = cw.GetOrCreateComInterfaceForObject(utf16, CreateComInterfaceFlags.None); + var utf16ComObject = (IUTF16Marshalling)cw.GetOrCreateObjectForComInstance(utf16ComInstance, CreateObjectFlags.None); + Assert.Equal(utf16.GetString(), utf16ComObject.GetString()); + utf16.SetString("Set from CLR object"); + Assert.Equal(utf16.GetString(), utf16ComObject.GetString()); + utf16ComObject.SetString("Set from COM object"); + Assert.Equal(utf16.GetString(), utf16ComObject.GetString()); + + var customUtf16 = new CustomUtf16MarshalledClass(); + var customUtf16ComInstance = cw.GetOrCreateComInterfaceForObject(customUtf16, CreateComInterfaceFlags.None); + var customUtf16ComObject = (ICustomStringMarshallingUtf16)cw.GetOrCreateObjectForComInstance(customUtf16ComInstance, CreateObjectFlags.None); + Assert.Equal(customUtf16.GetString(), customUtf16ComObject.GetString()); + customUtf16.SetString("Set from CLR object"); + Assert.Equal(customUtf16.GetString(), customUtf16ComObject.GetString()); + customUtf16ComObject.SetString("Set from COM object"); + Assert.Equal(customUtf16.GetString(), customUtf16ComObject.GetString()); + } } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/ComInterfaceGenerator/StringMarshalling.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/ComInterfaceGenerator/StringMarshalling.cs index 316ab112d876b..9059f53c4cc8a 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/ComInterfaceGenerator/StringMarshalling.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/ComInterfaceGenerator/StringMarshalling.cs @@ -2,9 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Runtime.InteropServices.Marshalling; using System.Text; using System.Threading.Tasks; using SharedTypes.ComInterfaces; @@ -12,101 +15,187 @@ namespace NativeExports.ComInterfaceGenerator { - public unsafe class StringMarshalling { - // Call from another assembly to get a ptr to make an RCW - [UnmanagedCallersOnly(EntryPoint = "new_get_and_set_int")] - public static void* CreateComObject() - { - MyComWrapper cw = new(); - var myObject = new ImplementingObject(); - nint ptr = cw.GetOrCreateComInterfaceForObject(myObject, CreateComInterfaceFlags.None); - - return (void*)ptr; - } - - class MyComWrapper : ComWrappers - { - static void* _s_comInterface1VTable = null; - static void* s_comInterface1VTable - { - get - { - if (MyComWrapper._s_comInterface1VTable != null) - return _s_comInterface1VTable; - void** vtable = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(GetAndSetInt), sizeof(void*) * 5); - GetIUnknownImpl(out var fpQueryInterface, out var fpAddReference, out var fpRelease); - vtable[0] = (void*)fpQueryInterface; - vtable[1] = (void*)fpAddReference; - vtable[2] = (void*)fpRelease; - vtable[3] = (delegate* unmanaged)&ImplementingObject.ABI.GetInt; - vtable[4] = (delegate* unmanaged)&ImplementingObject.ABI.SetInt; - _s_comInterface1VTable = vtable; - return _s_comInterface1VTable; - } - } - protected override ComInterfaceEntry* ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count) - { - if (obj is ImplementingObject) - { - ComInterfaceEntry* comInterfaceEntry = (ComInterfaceEntry*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ImplementingObject), sizeof(ComInterfaceEntry)); - comInterfaceEntry->IID = new Guid(IGetAndSetInt._guid); - comInterfaceEntry->Vtable = (nint)s_comInterface1VTable; - count = 1; - return comInterfaceEntry; - } - count = 0; - return null; - } - - protected override object? CreateObject(nint externalComObject, CreateObjectFlags flags) => throw new NotImplementedException(); - protected override void ReleaseObjects(IEnumerable objects) => throw new NotImplementedException(); - } - - class ImplementingObject : IGetAndSetInt - { - int _data = 0; - - int IGetAndSetInt.GetInt() - { - return _data; - } - void IGetAndSetInt.SetInt(int x) - { - _data = x; - } - - // Provides function pointers in the COM format to use in COM VTables - public static class ABI - { - - [UnmanagedCallersOnly] - public static int GetInt(void* @this, int* value) - { - try - { - *value = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)@this).GetInt(); - return 0; - } - catch (Exception e) - { - return e.HResult; - } - } - - [UnmanagedCallersOnly] - public static int SetInt(void* @this, int newValue) - { - try - { - ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)@this).SetInt(newValue); - return 0; - } - catch (Exception e) - { - return e.HResult; - } - } - } - } - } + public unsafe class StringMarshalling + { + [UnmanagedCallersOnly(EntryPoint = "new_utf8_marshalling")] + public static void* CreateUtf8ComObject() + { + MyComWrapper cw = new(); + var myObject = new Utf8Implementation(); + nint ptr = cw.GetOrCreateComInterfaceForObject(myObject, CreateComInterfaceFlags.None); + + return (void*)ptr; + } + + [UnmanagedCallersOnly(EntryPoint = "new_utf16_marshalling")] + public static void* CreateUtf16ComObject() + { + MyComWrapper cw = new(); + var myObject = new Utf16Implementation(); + nint ptr = cw.GetOrCreateComInterfaceForObject(myObject, CreateComInterfaceFlags.None); + + return (void*)ptr; + } + + class MyComWrapper : ComWrappers + { + static void* _s_comInterface1VTable = null; + static void* _s_comInterface2VTable = null; + static void* S_Utf8VTable + { + get + { + if (_s_comInterface1VTable != null) + return _s_comInterface1VTable; + void** vtable = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(GetAndSetInt), sizeof(void*) * 5); + GetIUnknownImpl(out var fpQueryInterface, out var fpAddReference, out var fpRelease); + vtable[0] = (void*)fpQueryInterface; + vtable[1] = (void*)fpAddReference; + vtable[2] = (void*)fpRelease; + vtable[3] = (delegate* unmanaged)&Utf8Implementation.ABI.GetStringUtf8; + vtable[4] = (delegate* unmanaged)&Utf8Implementation.ABI.SetStringUtf8; + _s_comInterface1VTable = vtable; + return _s_comInterface1VTable; + } + } + static void* S_Utf16VTable + { + get + { + if (_s_comInterface2VTable != null) + return _s_comInterface2VTable; + void** vtable = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(GetAndSetInt), sizeof(void*) * 5); + GetIUnknownImpl(out var fpQueryInterface, out var fpAddReference, out var fpRelease); + vtable[0] = (void*)fpQueryInterface; + vtable[1] = (void*)fpAddReference; + vtable[2] = (void*)fpRelease; + vtable[3] = (delegate* unmanaged)&Utf16Implementation.ABI.GetStringUtf16; + vtable[4] = (delegate* unmanaged)&Utf16Implementation.ABI.SetStringUtf16; + _s_comInterface2VTable = vtable; + return _s_comInterface2VTable; + } + } + + protected override ComInterfaceEntry* ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count) + { + if (obj is IUTF8Marshalling) + { + ComInterfaceEntry* comInterfaceEntry = (ComInterfaceEntry*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Utf8Implementation), sizeof(ComInterfaceEntry)); + comInterfaceEntry->IID = new Guid(IUTF8Marshalling._guid); + comInterfaceEntry->Vtable = (nint)S_Utf8VTable; + count = 1; + return comInterfaceEntry; + } + else if (obj is IUTF16Marshalling) + { + ComInterfaceEntry* comInterfaceEntry = (ComInterfaceEntry*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Utf16Implementation), sizeof(ComInterfaceEntry)); + comInterfaceEntry->IID = new Guid(IUTF16Marshalling._guid); + comInterfaceEntry->Vtable = (nint)S_Utf16VTable; + count = 1; + return comInterfaceEntry; + } + count = 0; + return null; + } + + protected override object? CreateObject(nint externalComObject, CreateObjectFlags flags) => throw new NotImplementedException(); + protected override void ReleaseObjects(IEnumerable objects) => throw new NotImplementedException(); + } + + class Utf8Implementation : IUTF8Marshalling + { + string _data = "Hello, World!"; + + string IUTF8Marshalling.GetString() + { + return _data; + } + void IUTF8Marshalling.SetString(string x) + { + _data = x; + } + + // Provides function pointers in the COM format to use in COM VTables + public static class ABI + { + [UnmanagedCallersOnly] + public static int GetStringUtf8(void* @this, byte** value) + { + try + { + string currValue = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)@this).GetString(); + *value = Utf8StringMarshaller.ConvertToUnmanaged(currValue); + return 0; + } + catch (Exception e) + { + return e.HResult; + } + } + + [UnmanagedCallersOnly] + public static int SetStringUtf8(void* @this, byte* newValue) + { + try + { + string value = Utf8StringMarshaller.ConvertToManaged(newValue); + ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)@this).SetString(value); + return 0; + } + catch (Exception e) + { + return e.HResult; + } + } + } + } + + class Utf16Implementation : IUTF16Marshalling + { + string _data = "Hello, World!"; + + string IUTF16Marshalling.GetString() + { + return _data; + } + void IUTF16Marshalling.SetString(string x) + { + _data = x; + } + + // Provides function pointers in the COM format to use in COM VTables + public static class ABI + { + [UnmanagedCallersOnly] + public static int GetStringUtf16(void* @this, ushort** value) + { + try + { + string currValue = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)@this).GetString(); + *value = Utf16StringMarshaller.ConvertToUnmanaged(currValue); + return 0; + } + catch (Exception e) + { + return e.HResult; + } + } + + [UnmanagedCallersOnly] + public static int SetStringUtf16(void* @this, ushort* newValue) + { + try + { + string value = Utf16StringMarshaller.ConvertToManaged(newValue); + ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)@this).SetString(value); + return 0; + } + catch (Exception e) + { + return e.HResult; + } + } + } + } + } } From e08c859080e9641770b829c5a74a906b02c897e6 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Wed, 17 May 2023 12:09:04 -0700 Subject: [PATCH 3/5] Undo formatting on ref declarations --- .../ref/System.Runtime.InteropServices.cs | 194 +++++++++--------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index 60ce5dc6782f3..c218273a37848 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -8,13 +8,13 @@ namespace System.Runtime.CompilerServices { [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] - [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter, Inherited=false)] public sealed partial class IDispatchConstantAttribute : System.Runtime.CompilerServices.CustomConstantAttribute { public IDispatchConstantAttribute() { } public override object Value { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter, Inherited=false)] public sealed partial class IUnknownConstantAttribute : System.Runtime.CompilerServices.CustomConstantAttribute { public IUnknownConstantAttribute() { } @@ -23,13 +23,13 @@ public IUnknownConstantAttribute() { } } namespace System.Runtime.InteropServices { - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Interface, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Interface, Inherited=false)] public sealed partial class AutomationProxyAttribute : System.Attribute { public AutomationProxyAttribute(bool val) { } public bool Value { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue, Inherited=false)] public sealed partial class ComAliasNameAttribute : System.Attribute { public ComAliasNameAttribute(string alias) { } @@ -58,7 +58,7 @@ public override void AddEventHandler(object target, System.Delegate handler) { } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] public override void RemoveEventHandler(object target, System.Delegate handler) { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited=false)] public sealed partial class ComCompatibleVersionAttribute : System.Attribute { public ComCompatibleVersionAttribute(int major, int minor, int build, int revision) { } @@ -67,17 +67,17 @@ public ComCompatibleVersionAttribute(int major, int minor, int build, int revisi public int MinorVersion { get { throw null; } } public int RevisionNumber { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.All, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.All, Inherited=false)] public sealed partial class ComConversionLossAttribute : System.Attribute { public ComConversionLossAttribute() { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false)] public sealed partial class ComRegisterFunctionAttribute : System.Attribute { public ComRegisterFunctionAttribute() { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false)] public sealed partial class ComUnregisterFunctionAttribute : System.Attribute { public ComUnregisterFunctionAttribute() { } @@ -93,20 +93,20 @@ public HandleCollector(string? name, int initialThreshold, int maximumThreshold) public void Add() { } public void Remove() { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited=false)] public sealed partial class ImportedFromTypeLibAttribute : System.Attribute { public ImportedFromTypeLibAttribute(string tlbFile) { } public string Value { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false, AllowMultiple = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false, AllowMultiple=false)] public sealed partial class ManagedToNativeComInteropStubAttribute : System.Attribute { public ManagedToNativeComInteropStubAttribute(System.Type classType, string methodName) { } public System.Type ClassType { get { throw null; } } public string MethodName { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited = false, AllowMultiple = true)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited=false, AllowMultiple=true)] public sealed partial class PrimaryInteropAssemblyAttribute : System.Attribute { public PrimaryInteropAssemblyAttribute(int major, int minor) { } @@ -125,7 +125,7 @@ public static partial class RuntimeEnvironment public static object GetRuntimeInterfaceAsObject(System.Guid clsid, System.Guid riid) { throw null; } public static string GetSystemVersion() { throw null; } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false)] public sealed partial class TypeLibFuncAttribute : System.Attribute { public TypeLibFuncAttribute(short flags) { } @@ -149,13 +149,13 @@ public enum TypeLibFuncFlags FReplaceable = 2048, FImmediateBind = 4096, } - [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited=false)] public sealed partial class TypeLibImportClassAttribute : System.Attribute { public TypeLibImportClassAttribute(System.Type importClass) { } public string Value { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited=false)] public sealed partial class TypeLibTypeAttribute : System.Attribute { public TypeLibTypeAttribute(short flags) { } @@ -180,7 +180,7 @@ public enum TypeLibTypeFlags FDispatchable = 4096, FReverseBind = 8192, } - [System.AttributeUsageAttribute(System.AttributeTargets.Field, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Field, Inherited=false)] public sealed partial class TypeLibVarAttribute : System.Attribute { public TypeLibVarAttribute(short flags) { } @@ -204,7 +204,7 @@ public enum TypeLibVarFlags FReplaceable = 2048, FImmediateBind = 4096, } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, Inherited=false)] public sealed partial class TypeLibVersionAttribute : System.Attribute { public TypeLibVersionAttribute(int major, int minor) { } @@ -370,8 +370,8 @@ public GeneratedComClassAttribute() { } public partial class GeneratedComInterfaceAttribute : System.Attribute { public GeneratedComInterfaceAttribute() { } - public StringMarshalling StringMarshalling { get{ throw null; } set { } } - public Type StringMarshallingCustomType { get{ throw null; } set { } } + public StringMarshalling StringMarshalling { get { throw null; } set { } } + public Type? StringMarshallingCustomType { get { throw null; } set { } } } [System.CLSCompliantAttribute(false)] public partial interface IComExposedClass @@ -549,7 +549,7 @@ public void Write(long position, ref T structure) where T : struct { } namespace System.Runtime.InteropServices { [System.ObsoleteAttribute("Code Access Security is not supported or honored by the runtime.", DiagnosticId = "SYSLIB0003", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] - [System.AttributeUsageAttribute(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, AllowMultiple=false, Inherited=false)] public sealed partial class AllowReversePInvokeCallsAttribute : System.Attribute { public AllowReversePInvokeCallsAttribute() { } @@ -567,7 +567,7 @@ public AllowReversePInvokeCallsAttribute() { } public static bool operator ==(System.Runtime.InteropServices.ArrayWithOffset a, System.Runtime.InteropServices.ArrayWithOffset b) { throw null; } public static bool operator !=(System.Runtime.InteropServices.ArrayWithOffset a, System.Runtime.InteropServices.ArrayWithOffset b) { throw null; } } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited=false)] public sealed partial class BestFitMappingAttribute : System.Attribute { public bool ThrowOnUnmappableChar; @@ -589,7 +589,7 @@ public enum CallingConvention ThisCall = 4, FastCall = 5, } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class, Inherited=false)] public sealed partial class ClassInterfaceAttribute : System.Attribute { public ClassInterfaceAttribute(short classInterfaceType) { } @@ -614,7 +614,7 @@ public enum ClassInterfaceType public override int GetHashCode() { throw null; } public override string ToString() { throw null; } } - [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited=false)] public sealed partial class CoClassAttribute : System.Attribute { public CoClassAttribute(System.Type coClass) { } @@ -627,13 +627,13 @@ public static partial class CollectionsMarshal public static ref TValue? GetValueRefOrAddDefault(System.Collections.Generic.Dictionary dictionary, TKey key, out bool exists) where TKey : notnull { throw null; } public static void SetCount(System.Collections.Generic.List list, int count) { throw null; } } - [System.AttributeUsageAttribute(System.AttributeTargets.Class, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Class, Inherited=false)] public sealed partial class ComDefaultInterfaceAttribute : System.Attribute { public ComDefaultInterfaceAttribute(System.Type defaultInterface) { } public System.Type Value { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited=false)] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public sealed partial class ComEventInterfaceAttribute : System.Attribute { @@ -661,7 +661,7 @@ public COMException(string? message, System.Exception? inner) { } public COMException(string? message, int errorCode) { } public override string ToString() { throw null; } } - [System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Interface, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Interface, Inherited=false)] public sealed partial class ComImportAttribute : System.Attribute { public ComImportAttribute() { } @@ -679,7 +679,7 @@ public enum ComMemberType PropGet = 1, PropSet = 2, } - [System.AttributeUsageAttribute(System.AttributeTargets.Class, Inherited = true)] + [System.AttributeUsageAttribute(System.AttributeTargets.Class, Inherited=true)] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public sealed partial class ComSourceInterfacesAttribute : System.Attribute { @@ -770,13 +770,13 @@ public enum CustomQueryInterfaceResult NotHandled = 1, Failed = 2, } - [System.AttributeUsageAttribute(System.AttributeTargets.Module, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Module, Inherited=false)] public sealed partial class DefaultCharSetAttribute : System.Attribute { public DefaultCharSetAttribute(System.Runtime.InteropServices.CharSet charSet) { } public System.Runtime.InteropServices.CharSet CharSet { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Method, AllowMultiple = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Method, AllowMultiple=false)] public sealed partial class DefaultDllImportSearchPathsAttribute : System.Attribute { public DefaultDllImportSearchPathsAttribute(System.Runtime.InteropServices.DllImportSearchPath paths) { } @@ -795,13 +795,13 @@ public sealed partial class DispatchWrapper public DispatchWrapper(object? obj) { } public object? WrappedObject { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Method | System.AttributeTargets.Property, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Method | System.AttributeTargets.Property, Inherited=false)] public sealed partial class DispIdAttribute : System.Attribute { public DispIdAttribute(int dispId) { } public int Value { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false)] public sealed partial class DllImportAttribute : System.Attribute { public bool BestFitMapping; @@ -827,7 +827,7 @@ public enum DllImportSearchPath System32 = 2048, SafeDirectories = 4096, } - [System.AttributeUsageAttribute(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Interface, AllowMultiple=false, Inherited=false)] public sealed class DynamicInterfaceCastableImplementationAttribute : Attribute { public DynamicInterfaceCastableImplementationAttribute() { } @@ -840,7 +840,7 @@ public ErrorWrapper(int errorCode) { } public ErrorWrapper(object errorCode) { } public int ErrorCode { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited=false)] public sealed partial class GuidAttribute : System.Attribute { public GuidAttribute(string guid) { } @@ -853,7 +853,7 @@ public readonly partial struct HandleRef public HandleRef(object? wrapper, System.IntPtr handle) { throw null; } public System.IntPtr Handle { get { throw null; } } public object? Wrapper { get { throw null; } } - public static explicit operator System.IntPtr(System.Runtime.InteropServices.HandleRef value) { throw null; } + public static explicit operator System.IntPtr (System.Runtime.InteropServices.HandleRef value) { throw null; } public static System.IntPtr ToIntPtr(System.Runtime.InteropServices.HandleRef value) { throw null; } } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] @@ -883,7 +883,7 @@ public partial interface IDynamicInterfaceCastable bool IsInterfaceImplemented(System.RuntimeTypeHandle interfaceType, bool throwIfNotImplemented); System.RuntimeTypeHandle GetInterfaceImplementation(System.RuntimeTypeHandle interfaceType); } - [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Interface, Inherited=false)] public sealed partial class InterfaceTypeAttribute : System.Attribute { public InterfaceTypeAttribute(short interfaceType) { } @@ -908,19 +908,19 @@ protected InvalidOleVariantTypeException(System.Runtime.Serialization.Serializat public InvalidOleVariantTypeException(string? message) { } public InvalidOleVariantTypeException(string? message, System.Exception? inner) { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false)] public sealed partial class LCIDConversionAttribute : System.Attribute { public LCIDConversionAttribute(int lcid) { } public int Value { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, AllowMultiple = false, Inherited=false)] public sealed partial class LibraryImportAttribute : System.Attribute { public LibraryImportAttribute(string libraryName) { } public string LibraryName { get { throw null; } } public string? EntryPoint { get { throw null; } set { } } - public bool SetLastError { get { throw null; } set { } } + public bool SetLastError { get { throw null; } set { }} public System.Runtime.InteropServices.StringMarshalling StringMarshalling { get { throw null; } set { } } public System.Type? StringMarshallingCustomType { get { throw null; } set { } } } @@ -1068,8 +1068,8 @@ public static void PrelinkAll(System.Type c) { } public static void PtrToStructure(System.IntPtr ptr, object structure) { } [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public static object? PtrToStructure(System.IntPtr ptr, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type structureType) { throw null; } - public static T? PtrToStructure<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] T>(System.IntPtr ptr) { throw null; } + public static object? PtrToStructure(System.IntPtr ptr, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors| System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type structureType) { throw null; } + public static T? PtrToStructure<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]T>(System.IntPtr ptr) { throw null; } public static void PtrToStructure(System.IntPtr ptr, [System.Diagnostics.CodeAnalysis.DisallowNullAttribute] T structure) { } public static int QueryInterface(System.IntPtr pUnk, ref System.Guid iid, out System.IntPtr ppv) { throw null; } public static byte ReadByte(System.IntPtr ptr) { throw null; } @@ -1184,7 +1184,7 @@ public static void ZeroFreeCoTaskMemUTF8(System.IntPtr s) { } public static void ZeroFreeGlobalAllocAnsi(System.IntPtr s) { } public static void ZeroFreeGlobalAllocUnicode(System.IntPtr s) { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.ReturnValue, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.ReturnValue, Inherited=false)] public sealed partial class MarshalAsAttribute : System.Attribute { public System.Runtime.InteropServices.UnmanagedType ArraySubType; @@ -1263,9 +1263,9 @@ public static void Free(void* ptr) { } public static System.Runtime.InteropServices.NFloat Pi { get { throw null; } } public static System.Runtime.InteropServices.NFloat PositiveInfinity { get { throw null; } } public static int Size { get { throw null; } } - static System.Runtime.InteropServices.NFloat System.Numerics.IAdditiveIdentity.AdditiveIdentity { get { throw null; } } + static System.Runtime.InteropServices.NFloat System.Numerics.IAdditiveIdentity.AdditiveIdentity { get { throw null; } } static System.Runtime.InteropServices.NFloat System.Numerics.IBinaryNumber.AllBitsSet { get { throw null; } } - static System.Runtime.InteropServices.NFloat System.Numerics.IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } + static System.Runtime.InteropServices.NFloat System.Numerics.IMultiplicativeIdentity.MultiplicativeIdentity { get { throw null; } } static System.Runtime.InteropServices.NFloat System.Numerics.INumberBase.One { get { throw null; } } static int System.Numerics.INumberBase.Radix { get { throw null; } } static System.Runtime.InteropServices.NFloat System.Numerics.INumberBase.Zero { get { throw null; } } @@ -1343,76 +1343,76 @@ public static void Free(void* ptr) { } public static System.Runtime.InteropServices.NFloat MinMagnitudeNumber(System.Runtime.InteropServices.NFloat x, System.Runtime.InteropServices.NFloat y) { throw null; } public static System.Runtime.InteropServices.NFloat MinNumber(System.Runtime.InteropServices.NFloat x, System.Runtime.InteropServices.NFloat y) { throw null; } public static System.Runtime.InteropServices.NFloat operator +(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } - public static explicit operator checked byte(System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator checked char(System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator checked short(System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator checked int(System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator checked long(System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator checked System.Int128(System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator checked nint(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked byte (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked char (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked short (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked int (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked long (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked System.Int128 (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked nint (System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator checked sbyte(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked sbyte (System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator checked ushort(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked ushort (System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator checked uint(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked uint (System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator checked ulong(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked ulong (System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator checked System.UInt128(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked System.UInt128 (System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator checked nuint(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator checked nuint (System.Runtime.InteropServices.NFloat value) { throw null; } public static System.Runtime.InteropServices.NFloat operator --(System.Runtime.InteropServices.NFloat value) { throw null; } public static System.Runtime.InteropServices.NFloat operator /(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } public static bool operator ==(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } - public static explicit operator System.Runtime.InteropServices.NFloat(decimal value) { throw null; } - public static explicit operator System.Runtime.InteropServices.NFloat(double value) { throw null; } - public static explicit operator System.Runtime.InteropServices.NFloat(System.Int128 value) { throw null; } - public static explicit operator byte(System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator char(System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator decimal(System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator System.Half(System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator System.Int128(System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator short(System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator int(System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator long(System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator nint(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator System.Runtime.InteropServices.NFloat (decimal value) { throw null; } + public static explicit operator System.Runtime.InteropServices.NFloat (double value) { throw null; } + public static explicit operator System.Runtime.InteropServices.NFloat (System.Int128 value) { throw null; } + public static explicit operator byte (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator char (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator decimal (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator System.Half (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator System.Int128 (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator short (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator int (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator long (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator nint (System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator sbyte(System.Runtime.InteropServices.NFloat value) { throw null; } - public static explicit operator float(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator sbyte (System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator float (System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator System.UInt128(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator System.UInt128 (System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator ushort(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator ushort (System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator uint(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator uint (System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator ulong(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator ulong (System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator nuint(System.Runtime.InteropServices.NFloat value) { throw null; } + public static explicit operator nuint (System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator System.Runtime.InteropServices.NFloat(System.UInt128 value) { throw null; } + public static explicit operator System.Runtime.InteropServices.NFloat (System.UInt128 value) { throw null; } public static bool operator >(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } public static bool operator >=(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat(byte value) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat(char value) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat(short value) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat(int value) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat(long value) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat(nint value) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat(System.Half value) { throw null; } - public static implicit operator double(System.Runtime.InteropServices.NFloat value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (byte value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (char value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (short value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (int value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (long value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (nint value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (System.Half value) { throw null; } + public static implicit operator double (System.Runtime.InteropServices.NFloat value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Runtime.InteropServices.NFloat(sbyte value) { throw null; } - public static implicit operator System.Runtime.InteropServices.NFloat(float value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (sbyte value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (float value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Runtime.InteropServices.NFloat(ushort value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (ushort value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Runtime.InteropServices.NFloat(uint value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (uint value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Runtime.InteropServices.NFloat(ulong value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (ulong value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Runtime.InteropServices.NFloat(nuint value) { throw null; } + public static implicit operator System.Runtime.InteropServices.NFloat (nuint value) { throw null; } public static System.Runtime.InteropServices.NFloat operator ++(System.Runtime.InteropServices.NFloat value) { throw null; } public static bool operator !=(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } public static bool operator <(System.Runtime.InteropServices.NFloat left, System.Runtime.InteropServices.NFloat right) { throw null; } @@ -1490,7 +1490,7 @@ public static void Free(void* ptr) { } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.IFormatProvider? provider, out System.Runtime.InteropServices.NFloat result) { throw null; } public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.Runtime.InteropServices.NFloat result) { throw null; } } - [System.AttributeUsageAttribute(System.AttributeTargets.Parameter, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Parameter, Inherited=false)] public sealed partial class OptionalAttribute : System.Attribute { public OptionalAttribute() { } @@ -1531,12 +1531,12 @@ internal PosixSignalRegistration() { } public void Dispose() { } ~PosixSignalRegistration() { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false)] public sealed partial class PreserveSigAttribute : System.Attribute { public PreserveSigAttribute() { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Class, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Class, Inherited=false)] public sealed partial class ProgIdAttribute : System.Attribute { public ProgIdAttribute(string progId) { } @@ -1580,7 +1580,7 @@ public enum StringMarshalling Utf8 = 1, Utf16 = 2, } - [System.AttributeUsageAttribute(System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, AllowMultiple = false, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, AllowMultiple=false, Inherited=false)] public sealed partial class TypeIdentifierAttribute : System.Attribute { public TypeIdentifierAttribute() { } @@ -1607,7 +1607,7 @@ public UnmanagedCallersOnlyAttribute() { } public System.Type[]? CallConvs; public string? EntryPoint; } - [System.AttributeUsageAttribute(System.AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Delegate, AllowMultiple=false, Inherited=false)] public sealed partial class UnmanagedFunctionPointerAttribute : System.Attribute { public bool BestFitMapping; @@ -2324,7 +2324,7 @@ public ref struct ManagedToUnmanagedIn { public static int BufferSize { get { throw null; } } public void FromManaged(string? managed, System.Span buffer) { throw null; } - public byte* ToUnmanaged() { throw null; } + public byte* ToUnmanaged() { throw null; } public void Free() { throw null; } } } @@ -2379,7 +2379,7 @@ public ref struct ManagedToUnmanagedIn { public static int BufferSize { get { throw null; } } public void FromManaged(string? managed, System.Span buffer) { throw null; } - public ushort* ToUnmanaged() { throw null; } + public ushort* ToUnmanaged() { throw null; } public void Free() { throw null; } } } @@ -2445,7 +2445,7 @@ public ref struct ManagedToUnmanagedIn { public static int BufferSize { get { throw null; } } public void FromManaged(string? managed, System.Span buffer) { throw null; } - public byte* ToUnmanaged() { throw null; } + public byte* ToUnmanaged() { throw null; } public void Free() { throw null; } } } From 1bc7b1eda0291c6983a49845558f40f9b7279bf1 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Wed, 17 May 2023 12:17:09 -0700 Subject: [PATCH 4/5] Add doc comments for StringMarshalling --- .../GeneratedComInterfaceAttribute.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/Marshalling/GeneratedComInterfaceAttribute.cs b/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/Marshalling/GeneratedComInterfaceAttribute.cs index d8a18b41182b4..cbe1a1508ba96 100644 --- a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/Marshalling/GeneratedComInterfaceAttribute.cs +++ b/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/Marshalling/GeneratedComInterfaceAttribute.cs @@ -6,7 +6,26 @@ namespace System.Runtime.InteropServices.Marshalling [AttributeUsage(AttributeTargets.Interface)] public class GeneratedComInterfaceAttribute : Attribute { + /// + /// Gets or sets how to marshal string arguments to all methods on the interface. + /// If the attributed interface inherits from another interface with , + /// it must have the same values for and . + /// + /// + /// If this field is set to a value other than , + /// must not be specified. + /// public StringMarshalling StringMarshalling { get; set; } + + /// + /// Gets or sets the used to control how string arguments are marshalled for all methods on the interface. + /// If the attributed interface inherits from another interface with , + /// it must have the same values for and . + /// + /// + /// If this field is specified, must not be specified + /// or must be set to . + /// public Type? StringMarshallingCustomType { get; set; } } } From 37d1b46a8413a5a1cbd294df82c20444d006c1c4 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Wed, 17 May 2023 14:01:47 -0700 Subject: [PATCH 5/5] PR feedback: Formatting, branch on nullable variable instead of null conditional access --- .../ComInterfaceGenerator.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs index 93f1d4287b49a..4165e7a77ec8a 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs @@ -242,7 +242,8 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M AttributeData? generatedComAttribute = null; foreach (var attr in symbol.ContainingType.GetAttributes()) { - if (generatedComAttribute is null && attr.AttributeClass?.ToDisplayString() == TypeNames.GeneratedComInterfaceAttribute) + if (generatedComAttribute is null + && attr.AttributeClass?.ToDisplayString() == TypeNames.GeneratedComInterfaceAttribute) { generatedComAttribute = attr; } @@ -256,10 +257,12 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M generatorDiagnostics.ReportConfigurationNotSupported(lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); } - var args = generatedComAttribute?.NamedArguments.ToImmutableDictionary(); - var iacd = new InteropAttributeCompilationData(); - if (args is not null) - iacd = iacd.WithValuesFromNamedArguments(args); + var generatedComInterfaceAttributeData = new InteropAttributeCompilationData(); + if (generatedComAttribute is not null) + { + var args = generatedComAttribute.NamedArguments.ToImmutableDictionary(); + generatedComInterfaceAttributeData = generatedComInterfaceAttributeData.WithValuesFromNamedArguments(args); + } // Create the stub. var signatureContext = SignatureContext.Create( symbol, @@ -267,7 +270,7 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M environment, generatorDiagnostics, symbol, - iacd, + generatedComInterfaceAttributeData, generatedComAttribute), environment, typeof(VtableIndexStubGenerator).Assembly);