From 7de517c993b63147a89fff5e4fcf4cda37e76706 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Tue, 16 May 2023 15:13:01 -0700 Subject: [PATCH 01/13] 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 85f01c4f9e0da1..01a1a930ae5ee5 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 410166893a514a..7629c68e9713c4 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 5f82435829d892..60ce5dc6782f33 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 7d81e174d96666..d8a18b41182b44 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 00000000000000..9d64ee3079a5ec --- /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 00000000000000..316ab112d876bd --- /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 00000000000000..d792b62d6d5a97 --- /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 00000000000000..2ef5534aa6b23d --- /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 00000000000000..2689425abd5065 --- /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 02/13] 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 9d64ee3079a5ec..175296047f8456 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 316ab112d876bd..9059f53c4cc8ae 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 03/13] 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 60ce5dc6782f33..c218273a378486 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 04/13] 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 d8a18b41182b44..cbe1a1508ba96a 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 05/13] 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 93f1d4287b49a7..4165e7a77ec8a3 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); From 6ae8b5013c98ca277d4ee329a307d0b1004d3d6a Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Thu, 18 May 2023 15:06:32 -0700 Subject: [PATCH 06/13] Warn on mismatch for stringmarshalling; warn if base canot be generated --- .../ComInterfaceContext.cs | 38 +++-- .../ComInterfaceGenerator.cs | 37 +++-- .../ComInterfaceGenerator/ComInterfaceInfo.cs | 24 ++- .../GeneratedComInterfaceAttributeData.cs | 69 +++++++++ .../GeneratorDiagnostics.cs | 22 +++ .../gen/ComInterfaceGenerator/LocationInfo.cs | 26 ++++ .../Resources/Strings.resx | 3 + .../Resources/xlf/Strings.cs.xlf | 5 + .../Resources/xlf/Strings.de.xlf | 5 + .../Resources/xlf/Strings.es.xlf | 5 + .../Resources/xlf/Strings.fr.xlf | 5 + .../Resources/xlf/Strings.it.xlf | 5 + .../Resources/xlf/Strings.ja.xlf | 5 + .../Resources/xlf/Strings.ko.xlf | 5 + .../Resources/xlf/Strings.pl.xlf | 5 + .../Resources/xlf/Strings.pt-BR.xlf | 5 + .../Resources/xlf/Strings.ru.xlf | 5 + .../Resources/xlf/Strings.tr.xlf | 5 + .../Resources/xlf/Strings.zh-Hans.xlf | 5 + .../Resources/xlf/Strings.zh-Hant.xlf | 5 + .../LibraryImportData.cs | 5 +- .../InteropAttributeData.cs | 1 + .../CodeSnippets.cs | 63 ++++++-- .../CompileFails.cs | 138 ++++++++++++++++++ .../GeneratedComInterfaceAttributeProvider.cs | 10 +- .../IComInterfaceAttributeProvider.cs | 2 +- .../IVirtualMethodIndexSignatureProvider.cs | 24 +-- .../VirtualMethodIndexAttributeProvider.cs | 8 +- .../ComInterfaces/IUTF8Marshalling.cs | 11 ++ 29 files changed, 477 insertions(+), 69 deletions(-) create mode 100644 src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratedComInterfaceAttributeData.cs create mode 100644 src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/LocationInfo.cs diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceContext.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceContext.cs index 0eee960740269a..4e45b452663d95 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceContext.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceContext.cs @@ -1,9 +1,11 @@ // 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.Collections.Immutable; using System.Threading; +using Microsoft.CodeAnalysis; namespace Microsoft.Interop { @@ -12,13 +14,13 @@ internal sealed record ComInterfaceContext(ComInterfaceInfo Info, ComInterfaceCo /// /// Takes a list of ComInterfaceInfo, and creates a list of ComInterfaceContext. /// - public static ImmutableArray GetContexts(ImmutableArray data, CancellationToken _) + public static ImmutableArray<(ComInterfaceContext? Context, Diagnostic? Diagnostic)> GetContexts(ImmutableArray data, CancellationToken _) { - Dictionary symbolToInterfaceInfoMap = new(); - var accumulator = ImmutableArray.CreateBuilder(data.Length); + Dictionary keyToInterfaceInfoMap = new(); + var accumulator = ImmutableArray.CreateBuilder<(ComInterfaceContext? Context, Diagnostic? Diagnostic)>(data.Length); foreach (var iface in data) { - symbolToInterfaceInfoMap.Add(iface.ThisInterfaceKey, iface); + keyToInterfaceInfoMap.Add(iface.ThisInterfaceKey, iface); } Dictionary symbolToContextMap = new(); @@ -28,28 +30,46 @@ public static ImmutableArray GetContexts(ImmutableArray data.Diagnostic is null) - .Select((data, ct) => - (data.InterfaceInfo, data.Symbol)); + .Select((data, ct) => (data.InterfaceInfo, data.Symbol)); - var interfaceContexts = interfaceSymbolsWithoutDiagnostics + var interfaceContextsAndDiagnostics = interfaceSymbolsWithoutDiagnostics .Select((data, ct) => data.InterfaceInfo!) .Collect() .SelectMany(ComInterfaceContext.GetContexts); + context.RegisterDiagnostics(interfaceContextsAndDiagnostics.Select((data, ct) => data.Diagnostic)); + var interfaceContexts = interfaceContextsAndDiagnostics + .Where(data => data.Context is not null) + .Select((data, ct) => data.Context!); + // Filter down interface symbols to remove those with diagnostics from GetContexts + interfaceSymbolsWithoutDiagnostics = interfaceSymbolsWithoutDiagnostics + .Zip(interfaceContextsAndDiagnostics) + .Where(data => data.Right.Diagnostic is null) + .Select((data, ct) => data.Left); var comMethodsAndSymbolsAndDiagnostics = interfaceSymbolsWithoutDiagnostics.Select(ComMethodInfo.GetMethodsFromInterface); context.RegisterDiagnostics(comMethodsAndSymbolsAndDiagnostics.SelectMany(static (methodList, ct) => methodList.Select(m => m.Diagnostic))); @@ -77,6 +86,10 @@ public void Initialize(IncrementalGeneratorInitializationContext context) .Zip(methodInfosGroupedByInterface) .Collect() .SelectMany(static (data, ct) => + { + return data.GroupBy(data => data.Left.GetTopLevelBase()); + }) + .SelectMany(static (data, ct) => { return ComMethodContext.CalculateAllMethods(data, ct); }); @@ -239,16 +252,6 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M } } - AttributeData? generatedComAttribute = null; - foreach (var attr in symbol.ContainingType.GetAttributes()) - { - if (generatedComAttribute is null - && attr.AttributeClass?.ToDisplayString() == TypeNames.GeneratedComInterfaceAttribute) - { - generatedComAttribute = attr; - } - } - var generatorDiagnostics = new GeneratorDiagnostics(); if (lcidConversionAttr is not null) @@ -257,12 +260,8 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M generatorDiagnostics.ReportConfigurationNotSupported(lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); } - var generatedComInterfaceAttributeData = new InteropAttributeCompilationData(); - if (generatedComAttribute is not null) - { - var args = generatedComAttribute.NamedArguments.ToImmutableDictionary(); - generatedComInterfaceAttributeData = generatedComInterfaceAttributeData.WithValuesFromNamedArguments(args); - } + GeneratedComInterfaceCompilationData.TryGetGeneratedComInterfaceAttributeFromInterface(symbol.ContainingType, out var generatedComAttribute); + var generatedComInterfaceAttributeData = GeneratedComInterfaceCompilationData.GetDataFromAttribute(generatedComAttribute); // Create the stub. var signatureContext = SignatureContext.Create( symbol, diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs index dd81de2507d4cb..aac332998ca902 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs @@ -20,7 +20,8 @@ internal sealed record ComInterfaceInfo( InterfaceDeclarationSyntax Declaration, ContainingSyntaxContext TypeDefinitionContext, ContainingSyntax ContainingSyntax, - Guid InterfaceId) + Guid InterfaceId, + LocationInfo DiagnosticLocation) { public static (ComInterfaceInfo? Info, Diagnostic? Diagnostic) From(INamedTypeSymbol symbol, InterfaceDeclarationSyntax syntax) { @@ -53,14 +54,25 @@ public static (ComInterfaceInfo? Info, Diagnostic? Diagnostic) From(INamedTypeSy if (!TryGetBaseComInterface(symbol, syntax, out INamedTypeSymbol? baseSymbol, out Diagnostic? baseDiagnostic)) return (null, baseDiagnostic); + if (baseSymbol is not null) + { + var baseAttrInfo = GeneratedComInterfaceData.From(GeneratedComInterfaceCompilationData.GetAttributeDataFromInterfaceSymbol(baseSymbol)); + var attrInfo = GeneratedComInterfaceData.From(GeneratedComInterfaceCompilationData.GetAttributeDataFromInterfaceSymbol(symbol)); + if (baseAttrInfo != attrInfo) + { + return (null, Diagnostic.Create(GeneratorDiagnostics.InvalidStringMarshallingMismatchBetweenBaseAndDerived, syntax.Identifier.GetLocation())); + } + } + return (new ComInterfaceInfo( - ManagedTypeInfo.CreateTypeInfoForTypeSymbol(symbol), + ManagedTypeInfo.CreateTypeInfoForTypeSymbol(symbol), symbol.ToDisplayString(), baseSymbol?.ToDisplayString(), - syntax, - new ContainingSyntaxContext(syntax), - new ContainingSyntax(syntax.Modifiers, syntax.Kind(), syntax.Identifier, syntax.TypeParameterList), - guid ?? Guid.Empty), null); + syntax, + new ContainingSyntaxContext(syntax), + new ContainingSyntax(syntax.Modifiers, syntax.Kind(), syntax.Identifier, syntax.TypeParameterList), + guid ?? Guid.Empty, + LocationInfo.From(symbol)), null); } /// diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratedComInterfaceAttributeData.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratedComInterfaceAttributeData.cs new file mode 100644 index 00000000000000..bb261b2b902c3e --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratedComInterfaceAttributeData.cs @@ -0,0 +1,69 @@ +// 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.Collections.Immutable; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Text; +using Microsoft.CodeAnalysis; + +namespace Microsoft.Interop +{ + /// + /// Contains the data related to a GeneratedComInterfaceAttribute, without references to Roslyn symbols. + /// See for a type with a reference to the StringMarshallingCustomType + /// + internal sealed record GeneratedComInterfaceData : InteropAttributeData + { + public static GeneratedComInterfaceData From(GeneratedComInterfaceCompilationData generatedComInterfaceAttr) + => new GeneratedComInterfaceData() with + { + IsUserDefined = generatedComInterfaceAttr.IsUserDefined, + SetLastError = generatedComInterfaceAttr.SetLastError, + StringMarshalling = generatedComInterfaceAttr.StringMarshalling, + StringMarshallingCustomType = generatedComInterfaceAttr.StringMarshallingCustomType is not null + ? ManagedTypeInfo.CreateTypeInfoForTypeSymbol(generatedComInterfaceAttr.StringMarshallingCustomType) + : null + }; + } + + /// + /// Contains the data related to a GeneratedComInterfaceAttribute, with references to Roslyn symbols. + /// Use instead when using for incremental compilation state to avoid keeping a compilation alive + /// + internal sealed record GeneratedComInterfaceCompilationData : InteropAttributeCompilationData + { + public static bool TryGetGeneratedComInterfaceAttributeFromInterface(INamedTypeSymbol interfaceSymbol, [NotNullWhen(true)] out AttributeData? generatedComInterfaceAttribute) + { + generatedComInterfaceAttribute = null; + foreach (var attr in interfaceSymbol.GetAttributes()) + { + if (generatedComInterfaceAttribute is null + && attr.AttributeClass?.ToDisplayString() == TypeNames.GeneratedComInterfaceAttribute) + { + generatedComInterfaceAttribute = attr; + } + } + return generatedComInterfaceAttribute is not null; + } + + public static GeneratedComInterfaceCompilationData GetAttributeDataFromInterfaceSymbol(INamedTypeSymbol interfaceSymbol) + { + bool found = TryGetGeneratedComInterfaceAttributeFromInterface(interfaceSymbol, out var attr); + Debug.Assert(found); + return GetDataFromAttribute(attr); + } + public static GeneratedComInterfaceCompilationData GetDataFromAttribute(AttributeData attr) + { + Debug.Assert(attr.AttributeClass.ToDisplayString() == TypeNames.GeneratedComInterfaceAttribute); + var generatedComInterfaceAttributeData = new GeneratedComInterfaceCompilationData(); + var args = attr.NamedArguments.ToImmutableDictionary(); + generatedComInterfaceAttributeData = generatedComInterfaceAttributeData.WithValuesFromNamedArguments(args); + return generatedComInterfaceAttributeData; + } + + } + +} diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs index 36fc49267fea03..fc389f64c9e6a1 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs @@ -24,6 +24,7 @@ public class Ids public const string InvalidGeneratedComInterfaceAttributeUsage = Prefix + "1092"; public const string MultipleComInterfaceBaseTypes = Prefix + "1093"; public const string AnalysisFailed = Prefix + "1094"; + public const string BaseInterfaceFailedGeneration = Prefix + "1095"; } private const string Category = "ComInterfaceGenerator"; @@ -58,6 +59,16 @@ public class Ids isEnabledByDefault: true, description: GetResourceString(nameof(SR.InvalidAttributedMethodDescription))); + public static readonly DiagnosticDescriptor InvalidStringMarshallingMismatchBetweenBaseAndDerived = + new DiagnosticDescriptor( + Ids.InvalidGeneratedComInterfaceAttributeUsage, + GetResourceString(nameof(SR.InvalidGeneratedComInterfaceAttributeUsageTitle)), + GetResourceString(nameof(SR.InvalidStringMarshallingConfigurationMessage)), + Category, + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.GeneratedComInterfaceStringMarshallingMustMatchBase))); + public static readonly DiagnosticDescriptor InvalidStringMarshallingConfiguration = new DiagnosticDescriptor( Ids.InvalidLibraryImportAttributeUsage, @@ -218,6 +229,17 @@ public class Ids isEnabledByDefault: true, description: GetResourceString(nameof(SR.AnalysisFailedDescription))); + public static readonly DiagnosticDescriptor BaseInterfaceIsNotGenerated = + new DiagnosticDescriptor( + //TODO: Strings + Ids.AnalysisFailed, + GetResourceString(nameof(SR.AnalysisFailedTitle)), + GetResourceString(nameof(SR.AnalysisFailedInterfaceMessage)), + Category, + DiagnosticSeverity.Warning, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.AnalysisFailedDescription))); + private readonly List _diagnostics = new List(); public IEnumerable Diagnostics => _diagnostics; diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/LocationInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/LocationInfo.cs new file mode 100644 index 00000000000000..473d5089f1c738 --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/LocationInfo.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Text; + +namespace Microsoft.Interop +{ + internal sealed record LocationInfo( + LinePositionSpan LinePositionSpan, + string FilePath, + TextSpan TextSpan) + { + public Location AsLocation() => Location.Create(FilePath, TextSpan, LinePositionSpan); + + public static LocationInfo From(ISymbol symbol) + { + var location = symbol.Locations[0]; + var lineSpan = location.GetLineSpan().Span; + var filePath = location.SourceTree.FilePath; + var textSpan = location.SourceSpan; + + return new LocationInfo(lineSpan, filePath, textSpan); + } + } +} diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx index 9c0cc44426487b..e780fb9148c9a0 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx @@ -249,4 +249,7 @@ Analysis for generation has failed. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + \ No newline at end of file diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf index 241afaa3a4af3b..f0aecb5f637260 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf @@ -57,6 +57,11 @@ Určenou konfiguraci nepodporují zdrojem generovaná volání P/Invokes. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + + Using 'GeneratedComInterfaceAttribute' and 'InterfaceTypeAttribute' is not supported with 'ComInterfaceType' value '{0}'. Použití GeneratedComInterfaceAttribute a InterfaceTypeAttribute se nepodporuje s hodnotou ComInterfaceType {0}. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf index 37cda7bfd599ba..3a63d1d5040d0e 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf @@ -57,6 +57,11 @@ Die angegebene Konfiguration wird von quellgenerierten P/Invokes nicht unterstützt. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + + Using 'GeneratedComInterfaceAttribute' and 'InterfaceTypeAttribute' is not supported with 'ComInterfaceType' value '{0}'. Die Verwendung von „GeneratedComInterfaceAttribute“ und „InterfaceTypeAttribute“ wird mit dem ComInterfaceType-Wert „{0}“ nicht unterstützt. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf index 71b79c45dd5206..e82e3ceb02e113 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf @@ -57,6 +57,11 @@ La configuración especificada no está admitida por P/Invokes de un generador de código fuente. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + + Using 'GeneratedComInterfaceAttribute' and 'InterfaceTypeAttribute' is not supported with 'ComInterfaceType' value '{0}'. No se admite el uso de "GeneratedComInterfaceAttribute" e "InterfaceTypeAttribute" con el valor "ComInterfaceType" '{0}'. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf index ed463398efa79c..18d2fc5ffe6ea9 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf @@ -57,6 +57,11 @@ La configuration spécifiée n’est pas prise en charge par les P/Invokes générés par la source. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + + Using 'GeneratedComInterfaceAttribute' and 'InterfaceTypeAttribute' is not supported with 'ComInterfaceType' value '{0}'. L’utilisation de 'GeneratedComInterfaceAttribute' et 'InterfaceTypeAttribute' n’est pas prise en charge avec la valeur 'ComInterfaceType' '{0}'. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf index bf2b7f5ef0065b..871da3b59011d5 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf @@ -57,6 +57,11 @@ La configurazione specificata non è supportata dai P/Invoke generati dall'origine. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + + Using 'GeneratedComInterfaceAttribute' and 'InterfaceTypeAttribute' is not supported with 'ComInterfaceType' value '{0}'. L'uso di 'GeneratedComInterfaceAttribute' e 'InterfaceTypeAttribute' non è supportato con il valore '{0}' di 'ComInterfaceType'. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf index c787e252ca99db..ed3bf75cee6979 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf @@ -57,6 +57,11 @@ 指定された構成は、ソースで生成された P/Invoke ではサポートされていません。 + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + + Using 'GeneratedComInterfaceAttribute' and 'InterfaceTypeAttribute' is not supported with 'ComInterfaceType' value '{0}'. 'GeneratedComInterfaceAttribute' および 'InterfaceTypeAttribute' は、'ComInterfaceType' の値 '{0}' ではサポートされていません。 diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf index 082dafc2a19f6e..402cb2b068dedb 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf @@ -57,6 +57,11 @@ 지정된 구성은 소스 생성 P/Invoke에서 지원되지 않습니다. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + + Using 'GeneratedComInterfaceAttribute' and 'InterfaceTypeAttribute' is not supported with 'ComInterfaceType' value '{0}'. 'GeneratedComInterfaceAttribute' 및 'InterfaceTypeAttribute'는 'ComInterfaceType' 값 '{0}'에서 지원되지 않습니다. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf index ec95453294f1e6..fecb1a50972101 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf @@ -57,6 +57,11 @@ Określona konfiguracja nie jest obsługiwana przez funkcję P/Invokes generowaną przez źródło. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + + Using 'GeneratedComInterfaceAttribute' and 'InterfaceTypeAttribute' is not supported with 'ComInterfaceType' value '{0}'. Użycie atrybutów „GeneratedComInterfaceAttribute” i „InterfaceTypeAttribute” nie jest obsługiwane w przypadku wartości „ComInterfaceType” „{0}”. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf index 03693164c2aab5..e285d47f3a75b9 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf @@ -57,6 +57,11 @@ A configuração especificada não tem suporte de P/Invokes gerados pela origem. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + + Using 'GeneratedComInterfaceAttribute' and 'InterfaceTypeAttribute' is not supported with 'ComInterfaceType' value '{0}'. Não há suporte para o uso de 'GeneratedComInterfaceAttribute' e 'InterfaceTypeAttribute' com o valor 'ComInterfaceType' '{0}'. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf index 83fef8b4d6caad..37c0fa3e254bdc 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf @@ -57,6 +57,11 @@ Указанная конфигурация не поддерживается в P/Invoke с созданием источника. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + + Using 'GeneratedComInterfaceAttribute' and 'InterfaceTypeAttribute' is not supported with 'ComInterfaceType' value '{0}'. Использование GeneratedComInterfaceAttribute и InterfaceTypeAttribute не поддерживается со значением ComInterfaceType "{0}". diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf index cefac4ef490f46..9cbc96d9b4f163 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf @@ -57,6 +57,11 @@ Belirtilen yapılandırma, kaynak tarafından oluşturulan P/Invokes tarafından desteklenmiyor. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + + Using 'GeneratedComInterfaceAttribute' and 'InterfaceTypeAttribute' is not supported with 'ComInterfaceType' value '{0}'. 'GeneratedComInterfaceAttribute' ve 'InterfaceTypeAttribute' kullanımı, 'ComInterfaceType' değeri '{0}' ile desteklenmiyor. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf index b8b39513669258..c66ea9049c444d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf @@ -57,6 +57,11 @@ 源生成的 P/Invoke 不支持指定的配置。 + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + + Using 'GeneratedComInterfaceAttribute' and 'InterfaceTypeAttribute' is not supported with 'ComInterfaceType' value '{0}'. “ComInterfaceType”值“{0}”不支持使用“GeneratedComInterfaceAttribute”和“InterfaceTypeAttribute”。 diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf index 83558aa5544983..8ea6fd3a1d5c7f 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf @@ -57,6 +57,11 @@ 来源產生的 P/Invokes 不支援指定的設定。 + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + + Using 'GeneratedComInterfaceAttribute' and 'InterfaceTypeAttribute' is not supported with 'ComInterfaceType' value '{0}'. 'ComInterfaceType' 值 '{0}' 不支援使用 'GeneratedComInterfaceAttribute' 和 'InterfaceTypeAttribute'。 diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportData.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportData.cs index 65691faf8beb3f..16a3b0687fe5d0 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportData.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportData.cs @@ -17,7 +17,10 @@ public static LibraryImportData From(LibraryImportCompilationData libraryImport) EntryPoint = libraryImport.EntryPoint, IsUserDefined = libraryImport.IsUserDefined, SetLastError = libraryImport.SetLastError, - StringMarshalling = libraryImport.StringMarshalling + StringMarshalling = libraryImport.StringMarshalling, + StringMarshallingCustomType = libraryImport.StringMarshallingCustomType is not null + ? ManagedTypeInfo.CreateTypeInfoForTypeSymbol(libraryImport.StringMarshallingCustomType) + : null, }; } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/InteropAttributeData.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/InteropAttributeData.cs index ecbb18426791ff..53ac6179540744 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/InteropAttributeData.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/InteropAttributeData.cs @@ -32,6 +32,7 @@ public record InteropAttributeData public InteropAttributeMember IsUserDefined { get; init; } public bool SetLastError { get; init; } public StringMarshalling StringMarshalling { get; init; } + public ManagedTypeInfo? StringMarshallingCustomType { get; init; } } /// diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs index 9a1ab29d002195..c54c0fc2cb9f74 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -38,7 +39,8 @@ private string VirtualMethodIndex( private string UnmanagedObjectUnwrapper(Type t) => _attributeProvider.UnmanagedObjectUnwrapper(t); - private string GeneratedComInterface => _attributeProvider.GeneratedComInterface; + private string GeneratedComInterface(StringMarshalling? stringMarshalling = null, Type? stringMarshallingCustomType = null) + => _attributeProvider.GeneratedComInterface(stringMarshalling, stringMarshallingCustomType); private string UnmanagedCallConv(Type[]? CallConvs = null) { @@ -55,7 +57,7 @@ private string UnmanagedCallConv(Type[]? CallConvs = null) using System.Runtime.InteropServices.Marshalling; {{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface INativeAPI { {{VirtualMethodIndex(0)}} @@ -70,7 +72,7 @@ partial interface INativeAPI using System.Runtime.InteropServices.Marshalling; {{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface INativeAPI { {{VirtualMethodIndex(0, ImplicitThisParameter: false)}} @@ -86,7 +88,7 @@ partial interface INativeAPI using System.Runtime.InteropServices.Marshalling; {{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface INativeAPI { @@ -122,7 +124,7 @@ public string BasicParametersAndModifiers(string typeName, string methodModifier [assembly:DisableRuntimeMarshalling] {{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface INativeAPI { {{VirtualMethodIndex(0)}} @@ -140,7 +142,7 @@ public string BasicParametersAndModifiersManagedToUnmanaged(string typeName, str [assembly:DisableRuntimeMarshalling] {{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface INativeAPI { {{VirtualMethodIndex(0, Direction: MarshalDirection.ManagedToUnmanaged)}} @@ -159,7 +161,7 @@ public string BasicParametersAndModifiersNoRef(string typeName, string preDeclar [assembly:DisableRuntimeMarshalling] {{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface INativeAPI { {{VirtualMethodIndex(0)}} @@ -175,7 +177,7 @@ public string BasicParametersAndModifiersNoImplicitThis(string typeName) => $$"" using System.Runtime.InteropServices.Marshalling; {{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface INativeAPI { {{VirtualMethodIndex(0, ImplicitThisParameter: false)}} @@ -193,7 +195,7 @@ public string MarshalUsingCollectionCountInfoParametersAndModifiers(string colle [assembly:DisableRuntimeMarshalling] {{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface INativeAPI { {{VirtualMethodIndex(0)}} @@ -219,7 +221,7 @@ public string BasicReturnTypeComExceptionHandling(string typeName, string preDec {{preDeclaration}} {{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface INativeAPI { {{VirtualMethodIndex(0, ExceptionMarshalling: ExceptionMarshalling.Com)}} @@ -236,7 +238,7 @@ public string BasicReturnTypeCustomExceptionHandling(string typeName, string cus {{preDeclaration}} {{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface INativeAPI { {{VirtualMethodIndex(0, ExceptionMarshallingType: Type.GetType(customExceptionType))}} @@ -250,12 +252,12 @@ partial interface INativeAPI using System.Runtime.InteropServices; using System.Runtime.InteropServices.Marshalling; - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface IComInterface { void Method(); } - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface IComInterface2 : IComInterface { void Method2(); @@ -266,22 +268,51 @@ partial interface IComInterface2 : IComInterface using System.Runtime.InteropServices; using System.Runtime.InteropServices.Marshalling; - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface IComInterface { void Method(); } - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface IOtherComInterface { void MethodA(); } - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface {|#0:IComInterface2|} : IComInterface, IOtherComInterface { void Method2(); } """; + + public string DerivedWithStringMarshalling(params + (StringMarshalling StringMarshalling, Type? StringMarshallingCustomType)[] attributeArguments) + { + List declarations = new(); + int i = 0; + foreach(var args in attributeArguments) + { + declarations.Add($$""" + {{GeneratedComInterface(args.StringMarshalling, args.StringMarshallingCustomType)}} + internal partial interface {|#{{i}}:IStringMarshalling{{i}}|} {{(i > 0 ? $": IStringMarshalling{i-1}" : "")}} + { + public string GetString{{i}}(); + public void SetString{{i}}(string value); + } + """); + i++; + } + return $$""" + using System; + using System.Runtime.InteropServices; + using System.Runtime.InteropServices.Marshalling; + + namespace SharedTypes.ComInterfaces + { + {{string.Join("\n\n", declarations)}} + } + """; + } public class ManagedToUnmanaged : IVirtualMethodIndexSignatureProvider { public MarshalDirection Direction => MarshalDirection.ManagedToUnmanaged; diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs index e4db5b789ec8ad..ade25dcb309a6e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs @@ -20,6 +20,10 @@ using VerifyComInterfaceGenerator = Microsoft.Interop.UnitTests.Verifiers.CSharpSourceGeneratorVerifier; using Microsoft.Interop; +using Newtonsoft.Json.Bson; +using System.Security.Cryptography.X509Certificates; +using System.Runtime.InteropServices.Marshalling; +using StringMarshalling = System.Runtime.InteropServices.StringMarshalling; namespace ComInterfaceGenerator.Unit.Tests { @@ -96,6 +100,132 @@ public static IEnumerable InvalidUnmanagedToManagedCodeSnippetsToCompi yield return new object[] { ID(), customStructMarshallingCodeSnippets.Stateful.ByValueInParameter, new[] { invalidUnmanagedToManagedParameterDiagnostic } }; } + public static IEnumerable StringMarshallingCodeSnippets(GeneratorKind generator) + { + CodeSnippets codeSnippets = new(GetAttributeProvider(generator)); + (StringMarshalling, Type?) utf8Marshalling = (StringMarshalling.Utf8, null); + (StringMarshalling, Type?) utf16Marshalling = (StringMarshalling.Utf16, null); + (StringMarshalling, Type?) customUtf16Marshalling = (StringMarshalling.Custom, typeof(Utf16StringMarshaller)); + DiagnosticResult[] emptyDiagnostics = new DiagnosticResult[] { }; + + yield return new object[] { + ID(), + codeSnippets.DerivedWithStringMarshalling(utf16Marshalling, utf16Marshalling), + emptyDiagnostics }; + yield return new object[] { + ID(), + codeSnippets.DerivedWithStringMarshalling(utf8Marshalling, utf8Marshalling), + emptyDiagnostics }; + yield return new object[] { + ID(), + codeSnippets.DerivedWithStringMarshalling(customUtf16Marshalling, customUtf16Marshalling), + emptyDiagnostics }; + + // mismatches + DiagnosticResult[] mismatchAt1 = MismatchesWithLocations(1); + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(utf8Marshalling, utf16Marshalling), + mismatchAt1 + }; + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(utf16Marshalling, utf8Marshalling), + mismatchAt1 + }; + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(utf16Marshalling, customUtf16Marshalling), + mismatchAt1 + }; + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(customUtf16Marshalling, utf16Marshalling), + mismatchAt1 + }; + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(utf8Marshalling, customUtf16Marshalling), + mismatchAt1 + }; + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(customUtf16Marshalling, utf8Marshalling), + mismatchAt1 + }; + + // Three levels inheritance + // Matching + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(utf8Marshalling, utf8Marshalling, utf8Marshalling), + emptyDiagnostics + }; + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(utf16Marshalling, utf16Marshalling, utf16Marshalling), + emptyDiagnostics + }; + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(customUtf16Marshalling, customUtf16Marshalling, customUtf16Marshalling), + emptyDiagnostics + }; + + //Mismatches + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(utf8Marshalling, utf8Marshalling, utf16Marshalling), + MismatchesWithLocations(2) + }; + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(utf8Marshalling, utf16Marshalling, utf16Marshalling), + MismatchesWithLocations(1).Concat(BaseCannotBeGeneratedWithLocations(2)).ToArray() + }; + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(utf8Marshalling, utf16Marshalling, utf8Marshalling), + MismatchesWithLocations(1, 2) + }; + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(utf8Marshalling, utf16Marshalling, customUtf16Marshalling), + MismatchesWithLocations(1, 2) + }; + + + DiagnosticResult[] MismatchesWithLocations(params int[] locations) + { + return locations + .Select(i => + new DiagnosticResult(GeneratorDiagnostics.InvalidStringMarshallingMismatchBetweenBaseAndDerived) + .WithLocation(i)) + .ToArray(); + } + DiagnosticResult[] BaseCannotBeGeneratedWithLocations(params int[] locations) + { + return locations + .Select(i => + new DiagnosticResult(GeneratorDiagnostics.BaseInterfaceIsNotGenerated) + .WithLocation(i)) + .ToArray(); + } + } + public static IEnumerable InvalidManagedToUnmanagedCodeSnippetsToCompile(GeneratorKind generator) { // Marshallers with only support for their expected places in the signatures in @@ -135,5 +265,13 @@ public async Task ValidateInvalidManagedToUnmanagedCodeSnippets(string id, strin .WithArguments("The specified parameter needs to be marshalled from managed to unmanaged, but the marshaller type 'global::Marshaller' does not support it.", "value"); await VerifyComInterfaceGenerator.VerifySourceGeneratorAsync(source, expectedDiagnostic); } + + [Theory] + [MemberData(nameof(StringMarshallingCodeSnippets), GeneratorKind.ComInterfaceGenerator)] + public async Task ValidateMismatchedStringMarshallingRaisesDiagnostic(string id, string source, DiagnosticResult[] expectedDiagnostics) + { + _ = id; + await VerifyComInterfaceGenerator.VerifySourceGeneratorAsync(source, expectedDiagnostics); + } } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/GeneratedComInterfaceAttributeProvider.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/GeneratedComInterfaceAttributeProvider.cs index 83bac9f792146c..b1bcef7a77d58e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/GeneratedComInterfaceAttributeProvider.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/GeneratedComInterfaceAttributeProvider.cs @@ -22,7 +22,15 @@ public string VirtualMethodIndex( public string UnmanagedObjectUnwrapper(Type t) => ""; - public string GeneratedComInterface => @$"[global::System.Runtime.InteropServices.Marshalling.GeneratedComInterface, global::System.Runtime.InteropServices.Guid(""0A52B77C-E08B-4274-A1F4-1A2BF2C07E60"")]"; + public string GeneratedComInterface(StringMarshalling? stringMarshalling = null, Type? stringMarshallingCustomType = null) + { + string comma = stringMarshalling is not null && stringMarshallingCustomType is not null ? ", " : ""; + return @$"[global::System.Runtime.InteropServices.Marshalling.GeneratedComInterface(" + + (stringMarshalling is not null ? $"StringMarshalling = {typeof(StringMarshalling).FullName}.{stringMarshalling!.Value}" : "") + + comma + + (stringMarshallingCustomType is not null ? $"StringMarshallingCustomType = typeof({stringMarshallingCustomType!.FullName})" : "") + + @$"), global::System.Runtime.InteropServices.Guid(""0A52B77C-E08B-4274-A1F4-1A2BF2C07E60"")]"; + } public string AdditionalUserRequiredInterfaces(string userDefinedInterfaceName) => ""; } diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/IComInterfaceAttributeProvider.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/IComInterfaceAttributeProvider.cs index f2df4929213013..84a0c09701469d 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/IComInterfaceAttributeProvider.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/IComInterfaceAttributeProvider.cs @@ -33,7 +33,7 @@ string VirtualMethodIndex( /// /// Returns the [GeneratedComInterface] to be put into a snippet, if desired. Otherwise, returns . /// - string GeneratedComInterface { get; } + string GeneratedComInterface(StringMarshalling? stringMarshalling = null, Type? stringMarshallingCustomType = null); /// /// Returns any additional code to be appended to the snippet that provides any additional interfaces the user must implement diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/IVirtualMethodIndexSignatureProvider.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/IVirtualMethodIndexSignatureProvider.cs index 04746077763d23..fde57878da80d4 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/IVirtualMethodIndexSignatureProvider.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/IVirtualMethodIndexSignatureProvider.cs @@ -30,7 +30,7 @@ string ICustomMarshallingSignatureTestProvider.BasicParametersAndModifiers(strin [assembly:DisableRuntimeMarshalling] {{AttributeProvider.UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{AttributeProvider.GeneratedComInterface}} + {{AttributeProvider.GeneratedComInterface()}} partial interface INativeAPI { {{AttributeProvider.VirtualMethodIndex(0, ImplicitThisParameter: ImplicitThisParameter, Direction: Direction)}} @@ -47,7 +47,7 @@ string ICustomMarshallingSignatureTestProvider.BasicParametersAndModifiersNoRef( [assembly:DisableRuntimeMarshalling] {{AttributeProvider.UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{AttributeProvider.GeneratedComInterface}} + {{AttributeProvider.GeneratedComInterface()}} partial interface INativeAPI { {{AttributeProvider.VirtualMethodIndex(0, ImplicitThisParameter: ImplicitThisParameter, Direction: Direction)}} @@ -63,7 +63,7 @@ string ICustomMarshallingSignatureTestProvider.BasicParameterByValue(string type {{preDeclaration}} {{AttributeProvider.UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{AttributeProvider.GeneratedComInterface}} + {{AttributeProvider.GeneratedComInterface()}} partial interface INativeAPI { {{AttributeProvider.VirtualMethodIndex(0, ImplicitThisParameter: ImplicitThisParameter, Direction: Direction)}} @@ -81,7 +81,7 @@ string ICustomMarshallingSignatureTestProvider.BasicParameterWithByRefModifier(s [assembly:DisableRuntimeMarshalling] {{AttributeProvider.UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{AttributeProvider.GeneratedComInterface}} + {{AttributeProvider.GeneratedComInterface()}} partial interface INativeAPI { {{AttributeProvider.VirtualMethodIndex(0, ImplicitThisParameter: ImplicitThisParameter, Direction: Direction)}} @@ -96,7 +96,7 @@ string ICustomMarshallingSignatureTestProvider.BasicReturnType(string typeName, {{preDeclaration}} {{AttributeProvider.UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{AttributeProvider.GeneratedComInterface}} + {{AttributeProvider.GeneratedComInterface()}} partial interface INativeAPI { {{AttributeProvider.VirtualMethodIndex(0, ImplicitThisParameter: ImplicitThisParameter, Direction: Direction)}} @@ -111,7 +111,7 @@ string ICustomMarshallingSignatureTestProvider.MarshalUsingParametersAndModifier {{preDeclaration}} {{AttributeProvider.UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{AttributeProvider.GeneratedComInterface}} + {{AttributeProvider.GeneratedComInterface()}} partial interface INativeAPI { {{AttributeProvider.VirtualMethodIndex(0, ImplicitThisParameter: ImplicitThisParameter, Direction: Direction)}} @@ -131,7 +131,7 @@ string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionCountInfoPa [assembly:DisableRuntimeMarshalling] {{AttributeProvider.UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{AttributeProvider.GeneratedComInterface}} + {{AttributeProvider.GeneratedComInterface()}} partial interface INativeAPI { {{AttributeProvider.VirtualMethodIndex(0, ImplicitThisParameter: ImplicitThisParameter, Direction: Direction)}} @@ -156,7 +156,7 @@ string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionParametersA [assembly:DisableRuntimeMarshalling] {{AttributeProvider.UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{AttributeProvider.GeneratedComInterface}} + {{AttributeProvider.GeneratedComInterface()}} partial interface INativeAPI { {{AttributeProvider.VirtualMethodIndex(0, ImplicitThisParameter: ImplicitThisParameter, Direction: Direction)}} @@ -182,7 +182,7 @@ string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionReturnValue [assembly:DisableRuntimeMarshalling] {{AttributeProvider.UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{AttributeProvider.GeneratedComInterface}} + {{AttributeProvider.GeneratedComInterface()}} partial interface INativeAPI { {{AttributeProvider.VirtualMethodIndex(0, ImplicitThisParameter: ImplicitThisParameter, Direction: Direction)}} @@ -202,7 +202,7 @@ string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionOutConstant [assembly:DisableRuntimeMarshalling] {{AttributeProvider.UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{AttributeProvider.GeneratedComInterface}} + {{AttributeProvider.GeneratedComInterface()}} partial interface INativeAPI { {{AttributeProvider.VirtualMethodIndex(0, ImplicitThisParameter: ImplicitThisParameter, Direction: Direction)}} @@ -221,7 +221,7 @@ string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionReturnConst [assembly:DisableRuntimeMarshalling] {{AttributeProvider.UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{AttributeProvider.GeneratedComInterface}} + {{AttributeProvider.GeneratedComInterface()}} partial interface INativeAPI { {{AttributeProvider.VirtualMethodIndex(0, ImplicitThisParameter: ImplicitThisParameter, Direction: Direction)}} @@ -239,7 +239,7 @@ string ICustomMarshallingSignatureTestProvider.CustomElementMarshalling(string c [assembly:DisableRuntimeMarshalling] {{AttributeProvider.UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}} - {{AttributeProvider.GeneratedComInterface}} + {{AttributeProvider.GeneratedComInterface()}} partial interface INativeAPI { {{AttributeProvider.VirtualMethodIndex(0, ImplicitThisParameter: ImplicitThisParameter, Direction: Direction)}} diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/VirtualMethodIndexAttributeProvider.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/VirtualMethodIndexAttributeProvider.cs index 0c31f2d61ffd2f..94553726a92ff2 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/VirtualMethodIndexAttributeProvider.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/VirtualMethodIndexAttributeProvider.cs @@ -23,15 +23,15 @@ public string VirtualMethodIndex( + (ImplicitThisParameter.HasValue ? $", ImplicitThisParameter = {ImplicitThisParameter.Value.ToString().ToLower()}" : "") + (Direction is not null ? $", Direction = {typeof(MarshalDirection).FullName}.{Direction.Value}" : "") + (StringMarshalling is not null ? $", StringMarshalling = {typeof(StringMarshalling).FullName}.{StringMarshalling!.Value}" : "") - + (StringMarshallingCustomType is not null ? $", StringMarshallingCustomType = {StringMarshallingCustomType!.FullName}" : "") + + (StringMarshallingCustomType is not null ? $", StringMarshallingCustomType = typeof({StringMarshallingCustomType!.FullName})" : "") + (SetLastError is not null ? $", SetLastError = {SetLastError.Value.ToString().ToLower()}" : "") + (ExceptionMarshalling is not null ? $", ExceptionMarshalling = {typeof(ExceptionMarshalling).FullName}.{ExceptionMarshalling.Value}" : "") - + (ExceptionMarshallingType is not null ? $", ExceptionMarshallingCustomType = {ExceptionMarshallingType!.FullName}" : "") + + (ExceptionMarshallingType is not null ? $", ExceptionMarshallingCustomType = typeof({ExceptionMarshallingType!.FullName})" : "") + ")]"; public string UnmanagedObjectUnwrapper(Type t) => $"[global::System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapperAttribute<{t.FullName!.Replace('+', '.')}>]"; - public string GeneratedComInterface => ""; + public string GeneratedComInterface(StringMarshalling? stringMarshalling = null, Type? stringMarshallingCustomType = null) => ""; public string AdditionalUserRequiredInterfaces(string userDefinedInterfaceName) => """ partial interface INativeAPI : IUnmanagedInterfaceType @@ -40,4 +40,4 @@ partial interface INativeAPI : IUnmanagedInterfaceType } """; } -} \ No newline at end of file +} 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 index 2689425abd5065..2efb13217bab88 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IUTF8Marshalling.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IUTF8Marshalling.cs @@ -17,4 +17,15 @@ internal partial interface IUTF8Marshalling public const string _guid = "E11D5F3E-DD57-41A6-A59E-7D110551A760"; } + + [Guid(_guid)] + [GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)] + internal partial interface IUTF16MarshallingFromIUTF8 + { + public string GetString2(); + + public void SetString2(string value); + + public const string _guid = "861A0AF1-067D-48F0-8592-F7F48EB88095"; + } } From 5299f8e57c2207dd1655f4927c7dfe4bd3334610 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Fri, 19 May 2023 09:58:31 -0700 Subject: [PATCH 07/13] Update StringMarshalling warinings --- .../ComInterfaceContext.cs | 18 +++---- .../ComInterfaceGenerator/ComInterfaceInfo.cs | 50 +++++++++++++++---- .../GeneratorDiagnostics.cs | 33 +++++++----- .../Resources/Strings.resx | 14 +++++- .../Resources/xlf/Strings.cs.xlf | 30 +++++++++-- .../Resources/xlf/Strings.de.xlf | 30 +++++++++-- .../Resources/xlf/Strings.es.xlf | 30 +++++++++-- .../Resources/xlf/Strings.fr.xlf | 30 +++++++++-- .../Resources/xlf/Strings.it.xlf | 30 +++++++++-- .../Resources/xlf/Strings.ja.xlf | 30 +++++++++-- .../Resources/xlf/Strings.ko.xlf | 30 +++++++++-- .../Resources/xlf/Strings.pl.xlf | 30 +++++++++-- .../Resources/xlf/Strings.pt-BR.xlf | 30 +++++++++-- .../Resources/xlf/Strings.ru.xlf | 30 +++++++++-- .../Resources/xlf/Strings.tr.xlf | 30 +++++++++-- .../Resources/xlf/Strings.zh-Hans.xlf | 30 +++++++++-- .../Resources/xlf/Strings.zh-Hant.xlf | 30 +++++++++-- .../CompileFails.cs | 40 ++++++++++++--- .../ComInterfaces/IUTF8Marshalling.cs | 17 +++++-- 19 files changed, 455 insertions(+), 107 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceContext.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceContext.cs index 4e45b452663d95..192d03b63cde07 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceContext.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceContext.cs @@ -16,13 +16,13 @@ internal sealed record ComInterfaceContext(ComInterfaceInfo Info, ComInterfaceCo /// public static ImmutableArray<(ComInterfaceContext? Context, Diagnostic? Diagnostic)> GetContexts(ImmutableArray data, CancellationToken _) { - Dictionary keyToInterfaceInfoMap = new(); + Dictionary nameToInterfaceInfoMap = new(); var accumulator = ImmutableArray.CreateBuilder<(ComInterfaceContext? Context, Diagnostic? Diagnostic)>(data.Length); foreach (var iface in data) { - keyToInterfaceInfoMap.Add(iface.ThisInterfaceKey, iface); + nameToInterfaceInfoMap.Add(iface.ThisInterfaceKey, iface); } - Dictionary symbolToContextMap = new(); + Dictionary nameToContextMap = new(); foreach (var iface in data) { @@ -32,7 +32,7 @@ internal sealed record ComInterfaceContext(ComInterfaceInfo Info, ComInterfaceCo (ComInterfaceContext? Context, Diagnostic? Diagnostic) AddContext(ComInterfaceInfo iface) { - if (symbolToContextMap.TryGetValue(iface.ThisInterfaceKey, out var cachedValue)) + if (nameToContextMap.TryGetValue(iface.ThisInterfaceKey, out var cachedValue)) { return (cachedValue, null); } @@ -40,25 +40,25 @@ internal sealed record ComInterfaceContext(ComInterfaceInfo Info, ComInterfaceCo if (iface.BaseInterfaceKey is null) { var baselessCtx = new ComInterfaceContext(iface, null); - symbolToContextMap[iface.ThisInterfaceKey] = baselessCtx; + nameToContextMap[iface.ThisInterfaceKey] = baselessCtx; return (baselessCtx, null); } - if (!symbolToContextMap.TryGetValue(iface.BaseInterfaceKey, out var baseContext)) + if (!nameToContextMap.TryGetValue(iface.BaseInterfaceKey, out var baseContext)) { - if(!keyToInterfaceInfoMap.TryGetValue(iface.BaseInterfaceKey, out var baseInfo)) + if(!nameToInterfaceInfoMap.TryGetValue(iface.BaseInterfaceKey, out var baseInfo)) { //Diagnostic that there is an issue with the base, so the interface cannot be return (null, Diagnostic.Create( GeneratorDiagnostics.BaseInterfaceIsNotGenerated, - iface.DiagnosticLocation.AsLocation())); + iface.DiagnosticLocation.AsLocation(), iface.ThisInterfaceKey, iface.BaseInterfaceKey)); } (baseContext, var baseDiag) = AddContext(baseInfo); } var ctx = new ComInterfaceContext(iface, baseContext); - symbolToContextMap[iface.ThisInterfaceKey] = ctx; + nameToContextMap[iface.ThisInterfaceKey] = ctx; return (ctx, null); } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs index aac332998ca902..0ffc58a15ce70e 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs @@ -54,15 +54,8 @@ public static (ComInterfaceInfo? Info, Diagnostic? Diagnostic) From(INamedTypeSy if (!TryGetBaseComInterface(symbol, syntax, out INamedTypeSymbol? baseSymbol, out Diagnostic? baseDiagnostic)) return (null, baseDiagnostic); - if (baseSymbol is not null) - { - var baseAttrInfo = GeneratedComInterfaceData.From(GeneratedComInterfaceCompilationData.GetAttributeDataFromInterfaceSymbol(baseSymbol)); - var attrInfo = GeneratedComInterfaceData.From(GeneratedComInterfaceCompilationData.GetAttributeDataFromInterfaceSymbol(symbol)); - if (baseAttrInfo != attrInfo) - { - return (null, Diagnostic.Create(GeneratorDiagnostics.InvalidStringMarshallingMismatchBetweenBaseAndDerived, syntax.Identifier.GetLocation())); - } - } + if (!StringMarshallingIsValid(symbol, syntax, baseSymbol, out Diagnostic? stringMarshallingDiagnostic)) + return (null, stringMarshallingDiagnostic); return (new ComInterfaceInfo( ManagedTypeInfo.CreateTypeInfoForTypeSymbol(symbol), @@ -75,6 +68,45 @@ public static (ComInterfaceInfo? Info, Diagnostic? Diagnostic) From(INamedTypeSy LocationInfo.From(symbol)), null); } + private static bool StringMarshallingIsValid(INamedTypeSymbol symbol, InterfaceDeclarationSyntax syntax, INamedTypeSymbol? baseSymbol, [NotNullWhen(false)] out Diagnostic? stringMarshallingDiagnostic) + { + var attrInfo = GeneratedComInterfaceData.From(GeneratedComInterfaceCompilationData.GetAttributeDataFromInterfaceSymbol(symbol)); + if (attrInfo.StringMarshalling is StringMarshalling.Custom && attrInfo.StringMarshallingCustomType is null) + { + stringMarshallingDiagnostic = Diagnostic.Create( + GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface, + syntax.Identifier.GetLocation(), + symbol.ToDisplayString(), + SR.InvalidStringMarshallingConfigurationMissingCustomType); + return false; + } + if (attrInfo.StringMarshalling is not StringMarshalling.Custom && attrInfo is not null) + { + stringMarshallingDiagnostic = Diagnostic.Create( + GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface, + syntax.Identifier.GetLocation(), + symbol.ToDisplayString(), + SR.InvalidStringMarshallingConfigurationNotCustom); + return false; + } + if (baseSymbol is not null) + { + var baseAttrInfo = GeneratedComInterfaceData.From(GeneratedComInterfaceCompilationData.GetAttributeDataFromInterfaceSymbol(baseSymbol)); + if (baseAttrInfo != attrInfo) + { + stringMarshallingDiagnostic = Diagnostic.Create( + GeneratorDiagnostics.InvalidStringMarshallingMismatchBetweenBaseAndDerived, + syntax.Identifier.GetLocation(), + symbol.ToDisplayString(), + SR.GeneratedComInterfaceStringMarshallingMustMatchBase); + return false; + } + } + stringMarshallingDiagnostic = null; + return true; + + } + /// /// Returns true if there is 0 or 1 base Com interfaces (i.e. the inheritance is valid), and returns false when there are 2 or more base Com interfaces and sets . /// diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs index fc389f64c9e6a1..a5b26ae327ff74 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs @@ -63,17 +63,27 @@ public class Ids new DiagnosticDescriptor( Ids.InvalidGeneratedComInterfaceAttributeUsage, GetResourceString(nameof(SR.InvalidGeneratedComInterfaceAttributeUsageTitle)), - GetResourceString(nameof(SR.InvalidStringMarshallingConfigurationMessage)), + GetResourceString(nameof(SR.InvalidStringMarshallingConfigurationOnInterfaceMessage)), Category, DiagnosticSeverity.Error, isEnabledByDefault: true, description: GetResourceString(nameof(SR.GeneratedComInterfaceStringMarshallingMustMatchBase))); - public static readonly DiagnosticDescriptor InvalidStringMarshallingConfiguration = + public static readonly DiagnosticDescriptor InvalidStringMarshallingConfigurationOnMethod = new DiagnosticDescriptor( Ids.InvalidLibraryImportAttributeUsage, GetResourceString(nameof(SR.InvalidVirtualMethodIndexAttributeUsage)), - GetResourceString(nameof(SR.InvalidStringMarshallingConfigurationMessage)), + GetResourceString(nameof(SR.InvalidStringMarshallingConfigurationOnMethodMessage)), + Category, + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.InvalidStringMarshallingConfigurationDescription))); + + public static readonly DiagnosticDescriptor InvalidStringMarshallingConfigurationOnInterface = + new DiagnosticDescriptor( + Ids.InvalidGeneratedComInterfaceAttributeUsage, + GetResourceString(nameof(SR.InvalidGeneratedComInterfaceAttributeUsageTitle)), + GetResourceString(nameof(SR.InvalidStringMarshallingConfigurationOnInterfaceMessage)), Category, DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -215,7 +225,7 @@ public class Ids GetResourceString(nameof(SR.AnalysisFailedTitle)), GetResourceString(nameof(SR.AnalysisFailedMethodMessage)), Category, - DiagnosticSeverity.Warning, + DiagnosticSeverity.Error, isEnabledByDefault: true, description: GetResourceString(nameof(SR.AnalysisFailedDescription))); @@ -225,20 +235,19 @@ public class Ids GetResourceString(nameof(SR.AnalysisFailedTitle)), GetResourceString(nameof(SR.AnalysisFailedInterfaceMessage)), Category, - DiagnosticSeverity.Warning, + DiagnosticSeverity.Error, isEnabledByDefault: true, description: GetResourceString(nameof(SR.AnalysisFailedDescription))); public static readonly DiagnosticDescriptor BaseInterfaceIsNotGenerated = new DiagnosticDescriptor( - //TODO: Strings - Ids.AnalysisFailed, - GetResourceString(nameof(SR.AnalysisFailedTitle)), - GetResourceString(nameof(SR.AnalysisFailedInterfaceMessage)), + Ids.BaseInterfaceFailedGeneration, + GetResourceString(nameof(SR.BaseInterfaceCannotBeGeneratedTitle)), + GetResourceString(nameof(SR.BaseInterfaceCannotBeGeneratedMessage)), Category, - DiagnosticSeverity.Warning, + DiagnosticSeverity.Error, isEnabledByDefault: true, - description: GetResourceString(nameof(SR.AnalysisFailedDescription))); + description: GetResourceString(nameof(SR.BaseInterfaceCannotBeGeneratedDescription))); private readonly List _diagnostics = new List(); @@ -258,7 +267,7 @@ public void ReportInvalidStringMarshallingConfiguration( { _diagnostics.Add( attributeData.CreateDiagnostic( - GeneratorDiagnostics.InvalidStringMarshallingConfiguration, + GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnMethod, methodName, detailsMessage)); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx index e780fb9148c9a0..aff9bd9830339d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx @@ -141,7 +141,7 @@ The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' is invalid. - + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} {1} is a message containing additional details about what is not valid @@ -252,4 +252,16 @@ The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. + + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + + + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + + + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + \ No newline at end of file diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf index f0aecb5f637260..86b3d1eee493b9 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf @@ -22,6 +22,21 @@ Analysis for generation has failed. + + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + + + + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + + + + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + + Source-generated P/Invokes will ignore any configuration that is not supported. Zdrojem generovaná volání P/Invokes budou ignorovat všechny nepodporované konfigurace. @@ -137,11 +152,6 @@ Konfigurace StringMarshalling a StringMarshallingCustomType je neplatná. - - The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} - Konfigurace StringMarshalling a StringMarshallingCustomType u metody {0} je neplatná. {1} - {1} is a message containing additional details about what is not valid - 'StringMarshallingCustomType' must be specified when 'StringMarshalling' is set to 'StringMarshalling.Custom'. StringMarshallingCustomType musí být určený, pokud je StringMarshalling nastavený na StringMarshalling.Custom. @@ -152,6 +162,16 @@ StringMarshalling by měl být nastavený na StringMarshalling.Custom, když je pokud je určený StringMarshallingCustomType. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + + + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + {1} is a message containing additional details about what is not valid + Invalid 'VirtualMethodIndexAttribute' usage Neplatné použití VirtualMethodIndexAttribute diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf index 3a63d1d5040d0e..8c663985398399 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf @@ -22,6 +22,21 @@ Analysis for generation has failed. + + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + + + + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + + + + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + + Source-generated P/Invokes will ignore any configuration that is not supported. Quellgenerierte P/Invokes ignorieren alle Konfigurationen, die nicht unterstützt werden. @@ -137,11 +152,6 @@ Die Konfiguration von \"StringMarshalling\" und \"StringMarshallingCustomType\" ist ungültig. - - The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} - Die Konfiguration von \"StringMarshalling\" und \"StringMarshallingCustomType\" für die Methode \"{0}\" ist ungültig. {1} - {1} is a message containing additional details about what is not valid - 'StringMarshallingCustomType' must be specified when 'StringMarshalling' is set to 'StringMarshalling.Custom'. \"StringMarshallingCustomType\" muss angegeben werden, wenn \"StringMarshalling\" auf \"StringMarshalling.Custom\" festgelegt ist. @@ -152,6 +162,16 @@ \"StringMarshalling\" muss auf \"StringMarshalling.Custom\" festgelegt werden, wenn \"StringMarshallingCustomType\" angegeben ist. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + + + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + {1} is a message containing additional details about what is not valid + Invalid 'VirtualMethodIndexAttribute' usage Ungültige Verwendung von „VirtualMethodIndexAttribute“ diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf index e82e3ceb02e113..282bc919d900a1 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf @@ -22,6 +22,21 @@ Analysis for generation has failed. + + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + + + + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + + + + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + + Source-generated P/Invokes will ignore any configuration that is not supported. Los P/Invoke de un generador de código fuente omitirán cualquier configuración que no esté admitida. @@ -137,11 +152,6 @@ La configuración de “StringMarshalling” y “StringMarshallingCustomType” no es válida. - - The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} - La configuración de “StringMarshalling” y “StringMarshallingCustomType” en el método “{0}” no es válida. {1} - {1} is a message containing additional details about what is not valid - 'StringMarshallingCustomType' must be specified when 'StringMarshalling' is set to 'StringMarshalling.Custom'. Se debe especificar “StringMarshallingCustomType” cuando “StringMarshalling” esté establecido en “StringMarshalling.Custom”. @@ -152,6 +162,16 @@ “StringMarshalling” debe establecerse en “StringMarshalling.Custom” cuando “StringMarshallingCustomType” esté especificado. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + + + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + {1} is a message containing additional details about what is not valid + Invalid 'VirtualMethodIndexAttribute' usage Uso de ”VirtualMethodIndexAttribute” no válido diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf index 18d2fc5ffe6ea9..74c670d705788c 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf @@ -22,6 +22,21 @@ Analysis for generation has failed. + + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + + + + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + + + + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + + Source-generated P/Invokes will ignore any configuration that is not supported. Les P/Invokes générés par la source ignorent toute configuration qui n’est pas prise en charge. @@ -137,11 +152,6 @@ La configuration de « StringMarshalling » et de « StringMarshallingCustomType » n’est pas valide. - - The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} - La configuration de « StringMarshalling » et de « StringMarshallingCustomType » n’est sur la méthode « {0} » pas valide. {1} - {1} is a message containing additional details about what is not valid - 'StringMarshallingCustomType' must be specified when 'StringMarshalling' is set to 'StringMarshalling.Custom'. « StringMarshallingCustomType » doit être spécifié quand « StringMarshalling » a la valeur « StringMarshalling.Custom ». @@ -152,6 +162,16 @@ « StringMarshalling » doit être défini sur « StringMarshalling.Custom » quand « StringMarshallingCustomType » est spécifié. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + + + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + {1} is a message containing additional details about what is not valid + Invalid 'VirtualMethodIndexAttribute' usage Utilisation de « VirtualMethodIndexAttribute » non valide diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf index 871da3b59011d5..53c8f37814aa1d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf @@ -22,6 +22,21 @@ Analysis for generation has failed. + + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + + + + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + + + + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + + Source-generated P/Invokes will ignore any configuration that is not supported. I P/Invoke generati dall'origine ignoreranno qualsiasi configurazione non supportata. @@ -137,11 +152,6 @@ La configurazione di 'StringMarshalling' e 'StringMarshallingCustomType' non è valida. - - The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} - La configurazione di 'StringMarshalling' e 'StringMarshallingCustomType' nel metodo '{0}' non è valida. {1} - {1} is a message containing additional details about what is not valid - 'StringMarshallingCustomType' must be specified when 'StringMarshalling' is set to 'StringMarshalling.Custom'. È necessario specificare 'StringMarshallingCustomType' quando 'StringMarshalling' è impostato su 'StringMarshalling.Custom'. @@ -152,6 +162,16 @@ 'StringMarshalling' deve essere impostato su 'StringMarshalling.Custom' quando è specificato 'StringMarshallingCustomType'. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + + + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + {1} is a message containing additional details about what is not valid + Invalid 'VirtualMethodIndexAttribute' usage Utilizzo di 'VirtualMethodIndexAttribute' non valido diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf index ed3bf75cee6979..f352c7cd2881cd 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf @@ -22,6 +22,21 @@ Analysis for generation has failed. + + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + + + + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + + + + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + + Source-generated P/Invokes will ignore any configuration that is not supported. ソース生成済みの P/Invoke は、サポートされていない構成を無視します。 @@ -137,11 +152,6 @@ 'StringMarshalling' と 'StringMarshallingCustomType' の構成が無効です。 - - The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} - メソッド '{0}' の 'StringMarshalling' と 'StringMarshallingCustomType' の構成が無効です。{1} - {1} is a message containing additional details about what is not valid - 'StringMarshallingCustomType' must be specified when 'StringMarshalling' is set to 'StringMarshalling.Custom'. 'StringMarshalling' が 'StringMarshalling.Custom' に設定されている場合は、'StringMarshallingCustomType' を指定する必要があります。 @@ -152,6 +162,16 @@ 'StringMarshallingCustomType' が指定されている場合、'StringMarshalling' を 'StringMarshalling.Custom' に設定する必要があります。 + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + + + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + {1} is a message containing additional details about what is not valid + Invalid 'VirtualMethodIndexAttribute' usage 'VirtualMethodIndexAttribute' の使用法が無効です diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf index 402cb2b068dedb..345e5c5cd76951 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf @@ -22,6 +22,21 @@ Analysis for generation has failed. + + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + + + + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + + + + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + + Source-generated P/Invokes will ignore any configuration that is not supported. 소스 생성 P/Invoke는 지원되지 않는 구성을 무시합니다. @@ -137,11 +152,6 @@ 'StringMarshalling' 및 'StringMarshallingCustomType'의 구성이 잘못되었습니다. - - The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} - '{0}' 메서드의 'StringMarshalling' 및 'StringMarshallingCustomType' 구성이 잘못되었습니다. {1} - {1} is a message containing additional details about what is not valid - 'StringMarshallingCustomType' must be specified when 'StringMarshalling' is set to 'StringMarshalling.Custom'. 'StringMarshalling'이 'StringMarshalling.Custom'으로 설정된 경우 'StringMarshallingCustomType'을 지정해야 합니다. @@ -152,6 +162,16 @@ 'StringMarshallingCustomType'이 지정된 경우 'StringMarshalling'은 'StringMarshalling.Custom'으로 설정되어야 합니다. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + + + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + {1} is a message containing additional details about what is not valid + Invalid 'VirtualMethodIndexAttribute' usage 잘못된 'VirtualMethodIndexAttribute' 사용 diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf index fecb1a50972101..c5a4ec99c7b408 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf @@ -22,6 +22,21 @@ Analysis for generation has failed. + + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + + + + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + + + + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + + Source-generated P/Invokes will ignore any configuration that is not supported. Funkcja P/Invokes generowana przez źródło zignoruje każdą nieobsługiwaną konfigurację. @@ -137,11 +152,6 @@ Konfiguracja elementów „StringMarshalling” i „StringMarshallingCustomType” jest nieprawidłowa. - - The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} - Konfiguracja elementów „StringMarshalling” i „StringMarshallingCustomType” w metodzie „{0}” jest nieprawidłowa. {1} - {1} is a message containing additional details about what is not valid - 'StringMarshallingCustomType' must be specified when 'StringMarshalling' is set to 'StringMarshalling.Custom'. Element „StringMarshallingCustomType” należy określić, gdy element „StringMarshalling” ma wartość „StringMarshalling.Custom”. @@ -152,6 +162,16 @@ Element „StringMarshalling” należy ustawić na wartość „StringMarshalling.Custom”, gdy określono element „StringMarshallingCustomType”. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + + + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + {1} is a message containing additional details about what is not valid + Invalid 'VirtualMethodIndexAttribute' usage Nieprawidłowe użycie elementu "VirtualMethodIndexAttribute" diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf index e285d47f3a75b9..ed879ee45fd14d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf @@ -22,6 +22,21 @@ Analysis for generation has failed. + + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + + + + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + + + + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + + Source-generated P/Invokes will ignore any configuration that is not supported. P/Invokes gerados pela origem ignorarão qualquer configuração sem suporte. @@ -137,11 +152,6 @@ A configuração de 'StringMarshalling' e 'StringMarshallingCustomType' é inválida. - - The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} - A configuração de 'StringMarshalling' e 'StringMarshallingCustomType' no método '{0}' é inválida. {1} - {1} is a message containing additional details about what is not valid - 'StringMarshallingCustomType' must be specified when 'StringMarshalling' is set to 'StringMarshalling.Custom'. 'StringMarshallingCustomType' deve ser especificado quando 'StringMarshalling' está definido como 'StringMarshalling.Custom'. @@ -152,6 +162,16 @@ 'StringMarshalling' deve ser definido como 'StringMarshalling.Custom' quando 'StringMarshallingCustomType' for especificado. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + + + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + {1} is a message containing additional details about what is not valid + Invalid 'VirtualMethodIndexAttribute' usage Uso inválido de 'VirtualMethodIndexAttribute' diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf index 37c0fa3e254bdc..3c9960febafe2a 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf @@ -22,6 +22,21 @@ Analysis for generation has failed. + + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + + + + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + + + + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + + Source-generated P/Invokes will ignore any configuration that is not supported. P/Invoke с созданием источника будут игнорировать все неподдерживаемые конфигурации. @@ -137,11 +152,6 @@ Конфигурация \"StringMarshalling\" и \"StringMarshallingCustomType\" недопустима. - - The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} - Конфигурация \"StringMarshalling\" и \"StringMarshallingCustomType\" в методе \"{0}\" недопустима. {1} - {1} is a message containing additional details about what is not valid - 'StringMarshallingCustomType' must be specified when 'StringMarshalling' is set to 'StringMarshalling.Custom'. Если для \"StringMarshalling\" задано значение \"StringMarshalling.Custom\", необходимо указать \"StringMarshallingCustomType\". @@ -152,6 +162,16 @@ Если указано \"StringMarshallingCustomType\", для \"StringMarshalling\" следует задать значение \"StringMarshalling.Custom\". + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + + + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + {1} is a message containing additional details about what is not valid + Invalid 'VirtualMethodIndexAttribute' usage Недопустимое использование VirtualMethodIndexAttribute diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf index 9cbc96d9b4f163..59e76ee7212551 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf @@ -22,6 +22,21 @@ Analysis for generation has failed. + + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + + + + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + + + + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + + Source-generated P/Invokes will ignore any configuration that is not supported. Kaynak tarafından oluşturulan P/Invokes desteklenmeyen yapılandırmaları yok sayar. @@ -137,11 +152,6 @@ 'StringMarshalling' ve 'StringMarshallingCustomType' yapılandırması geçersiz. - - The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} - '{0}' metodundaki 'StringMarshalling' ve 'StringMarshallingCustomType' yapılandırması geçersiz. {1} - {1} is a message containing additional details about what is not valid - 'StringMarshallingCustomType' must be specified when 'StringMarshalling' is set to 'StringMarshalling.Custom'. 'StringMarshalling' 'StringMarshalling.Custom' olarak ayarlandığında 'StringMarshallingCustomType' belirtilmelidir. @@ -152,6 +162,16 @@ 'StringMarshallingCustomType' belirtilirken 'StringMarshalling', 'StringMarshalling.Custom' olarak ayarlanmalıdır. + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + + + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + {1} is a message containing additional details about what is not valid + Invalid 'VirtualMethodIndexAttribute' usage Geçersiz 'VirtualMethodIndexAttribute' kullanımı diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf index c66ea9049c444d..24623486ad4f44 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf @@ -22,6 +22,21 @@ Analysis for generation has failed. + + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + + + + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + + + + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + + Source-generated P/Invokes will ignore any configuration that is not supported. 源生成的 P/Invoke 将忽略任何不受支持的配置。 @@ -137,11 +152,6 @@ “StringMarshalling” 和 “StringMarshallingCustomType” 的配置无效。 - - The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} - 方法“{0}”上的 “StringMarshalling” 和 “StringMarshallingCustomType” 的配置无效。{1} - {1} is a message containing additional details about what is not valid - 'StringMarshallingCustomType' must be specified when 'StringMarshalling' is set to 'StringMarshalling.Custom'. 在 “StringMarshalling” 设置为 “StringMarshalling.Custom” 时,必须指定 “StringMarshallingCustomType”。 @@ -152,6 +162,16 @@ 在指定 “StringMarshallingCustomType” 时,应将 “StringMarshalling” 设置为 “StringMarshalling.Custom”。 + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + + + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + {1} is a message containing additional details about what is not valid + Invalid 'VirtualMethodIndexAttribute' usage “VirtualMethodIndexAttribute” 使用情况无效 diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf index 8ea6fd3a1d5c7f..af444b65152d1c 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf @@ -22,6 +22,21 @@ Analysis for generation has failed. + + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + + + + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. + + + + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + The base COM interface failed to generate source. ComInterfaceGenerator will not generate source for this interface. + + Source-generated P/Invokes will ignore any configuration that is not supported. 来源產生的 P/Invokes 將會忽略任何不支援的設定。 @@ -137,11 +152,6 @@ 'StringMarshalling' 和 'StringMarshallingCustomType' 的設定無效。 - - The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} - 方法 '{0}' 上的 'StringMarshalling' 和 'StringMarshallingCustomType' 設定無效。{1} - {1} is a message containing additional details about what is not valid - 'StringMarshallingCustomType' must be specified when 'StringMarshalling' is set to 'StringMarshalling.Custom'. 當 'StringMarshalling' 設定為 'StringMarshalling.Custom' 時,必須指定 'StringMarshallingCustomType'。 @@ -152,6 +162,16 @@ 指定 'StringMarshallingCustomType' 時,'StringMarshalling' 應設定為 'StringMarshalling.Custom'。 + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} + + + + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on method '{0}' is invalid. {1} + {1} is a message containing additional details about what is not valid + Invalid 'VirtualMethodIndexAttribute' usage 'VirtualMethodIndexAttribute' 使用方式無效 diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs index ade25dcb309a6e..d0f305de50e54e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs @@ -106,20 +106,43 @@ public static IEnumerable StringMarshallingCodeSnippets(GeneratorKind (StringMarshalling, Type?) utf8Marshalling = (StringMarshalling.Utf8, null); (StringMarshalling, Type?) utf16Marshalling = (StringMarshalling.Utf16, null); (StringMarshalling, Type?) customUtf16Marshalling = (StringMarshalling.Custom, typeof(Utf16StringMarshaller)); + (StringMarshalling, Type?) customWithNoType = (StringMarshalling.Custom, null); + (StringMarshalling, Type?) utf8WithType = (StringMarshalling.Custom, null); DiagnosticResult[] emptyDiagnostics = new DiagnosticResult[] { }; - yield return new object[] { + // Custom with + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(customWithNoType), + new DiagnosticResult[] { new DiagnosticResult(GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface).WithLocation(0) } + }; + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(utf8WithType), + new DiagnosticResult[] { new DiagnosticResult(GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface).WithLocation(0) } + }; + + // Inheritance no diagnostic + yield return new object[] + { ID(), codeSnippets.DerivedWithStringMarshalling(utf16Marshalling, utf16Marshalling), - emptyDiagnostics }; - yield return new object[] { + emptyDiagnostics + }; + yield return new object[] + { ID(), codeSnippets.DerivedWithStringMarshalling(utf8Marshalling, utf8Marshalling), - emptyDiagnostics }; - yield return new object[] { + emptyDiagnostics + }; + yield return new object[] + { ID(), codeSnippets.DerivedWithStringMarshalling(customUtf16Marshalling, customUtf16Marshalling), - emptyDiagnostics }; + emptyDiagnostics + }; // mismatches DiagnosticResult[] mismatchAt1 = MismatchesWithLocations(1); @@ -221,7 +244,8 @@ DiagnosticResult[] BaseCannotBeGeneratedWithLocations(params int[] locations) return locations .Select(i => new DiagnosticResult(GeneratorDiagnostics.BaseInterfaceIsNotGenerated) - .WithLocation(i)) + .WithLocation(i) + .WithArguments($"StringMarshalling{i}", $"StringMarshalling{i-1}", )) .ToArray(); } } @@ -268,7 +292,7 @@ public async Task ValidateInvalidManagedToUnmanagedCodeSnippets(string id, strin [Theory] [MemberData(nameof(StringMarshallingCodeSnippets), GeneratorKind.ComInterfaceGenerator)] - public async Task ValidateMismatchedStringMarshallingRaisesDiagnostic(string id, string source, DiagnosticResult[] expectedDiagnostics) + public async Task ValidateStringMarshallingDiagnostics(string id, string source, DiagnosticResult[] expectedDiagnostics) { _ = id; await VerifyComInterfaceGenerator.VerifySourceGeneratorAsync(source, expectedDiagnostics); 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 index 2efb13217bab88..7fc07515542b97 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IUTF8Marshalling.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IUTF8Marshalling.cs @@ -19,13 +19,24 @@ internal partial interface IUTF8Marshalling } [Guid(_guid)] - [GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)] - internal partial interface IUTF16MarshallingFromIUTF8 + [GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16, StringMarshallingCustomType = typeof(Utf8StringMarshaller))] + internal partial interface IUTF16MarshallingFromIUTF8 : IUTF8Marshalling { public string GetString2(); public void SetString2(string value); - public const string _guid = "861A0AF1-067D-48F0-8592-F7F48EB88095"; + public new const string _guid = "861A0AF1-067D-48F0-8592-F7F48EB88095"; + } + + [Guid(_guid)] + [GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16, StringMarshallingCustomType = typeof(Utf8StringMarshaller))] + internal partial interface IUTF16Marshalling2levels : IUTF16MarshallingFromIUTF8 + { + public string GetString3(); + + public void SetString3(string value); + + public new const string _guid = "861A0AF1-067D-48F0-8592-F7F48EB88095"; } } From a7b57b73a4f4d42aff9ed908bb4e5dd8ba3c4db0 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Fri, 19 May 2023 14:29:29 -0700 Subject: [PATCH 08/13] Define behavior for when base in invalid --- .../ComInterfaceGenerator/ComInterfaceInfo.cs | 37 +++++----- .../GeneratedComInterfaceAttributeData.cs | 3 +- .../Resources/Strings.resx | 58 ++++++++-------- .../Resources/xlf/Strings.cs.xlf | 4 +- .../Resources/xlf/Strings.de.xlf | 4 +- .../Resources/xlf/Strings.es.xlf | 4 +- .../Resources/xlf/Strings.fr.xlf | 4 +- .../Resources/xlf/Strings.it.xlf | 4 +- .../Resources/xlf/Strings.ja.xlf | 4 +- .../Resources/xlf/Strings.ko.xlf | 4 +- .../Resources/xlf/Strings.pl.xlf | 4 +- .../Resources/xlf/Strings.pt-BR.xlf | 4 +- .../Resources/xlf/Strings.ru.xlf | 4 +- .../Resources/xlf/Strings.tr.xlf | 4 +- .../Resources/xlf/Strings.zh-Hans.xlf | 4 +- .../Resources/xlf/Strings.zh-Hant.xlf | 4 +- .../CodeSnippets.cs | 2 +- .../CompileFails.cs | 67 +++++++++++++++++-- 18 files changed, 140 insertions(+), 79 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs index cfd2cb11a3e864..cfcf50eb49ed6c 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Linq; using Microsoft.CodeAnalysis; @@ -76,28 +77,34 @@ public static (ComInterfaceInfo? Info, Diagnostic? Diagnostic) From(INamedTypeSy private static bool StringMarshallingIsValid(INamedTypeSymbol symbol, InterfaceDeclarationSyntax syntax, INamedTypeSymbol? baseSymbol, [NotNullWhen(false)] out Diagnostic? stringMarshallingDiagnostic) { var attrInfo = GeneratedComInterfaceData.From(GeneratedComInterfaceCompilationData.GetAttributeDataFromInterfaceSymbol(symbol)); - if (attrInfo.StringMarshalling is StringMarshalling.Custom && attrInfo.StringMarshallingCustomType is null) + if (attrInfo.IsUserDefined.HasFlag(InteropAttributeMember.StringMarshalling) || attrInfo.IsUserDefined.HasFlag(InteropAttributeMember.StringMarshallingCustomType)) { - stringMarshallingDiagnostic = Diagnostic.Create( - GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface, - syntax.Identifier.GetLocation(), - symbol.ToDisplayString(), - SR.InvalidStringMarshallingConfigurationMissingCustomType); + if (attrInfo.StringMarshalling is StringMarshalling.Custom && attrInfo.StringMarshallingCustomType is null) + { + stringMarshallingDiagnostic = Diagnostic.Create( + GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface, + syntax.Identifier.GetLocation(), + symbol.ToDisplayString(), + SR.InvalidStringMarshallingConfigurationMissingCustomType); return false; - } - if (attrInfo.StringMarshalling is not StringMarshalling.Custom && attrInfo is not null) - { - stringMarshallingDiagnostic = Diagnostic.Create( - GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface, - syntax.Identifier.GetLocation(), - symbol.ToDisplayString(), - SR.InvalidStringMarshallingConfigurationNotCustom); + } + if (attrInfo.StringMarshalling is not StringMarshalling.Custom && attrInfo.StringMarshallingCustomType is not null) + { + stringMarshallingDiagnostic = Diagnostic.Create( + GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface, + syntax.Identifier.GetLocation(), + symbol.ToDisplayString(), + SR.InvalidStringMarshallingConfigurationNotCustom); return false; + } } if (baseSymbol is not null) { + var baseAttrInfo = GeneratedComInterfaceData.From(GeneratedComInterfaceCompilationData.GetAttributeDataFromInterfaceSymbol(baseSymbol)); - if (baseAttrInfo != attrInfo) + // The base can be undefined string marshalling + if ((baseAttrInfo.IsUserDefined.HasFlag(InteropAttributeMember.StringMarshalling) || baseAttrInfo.IsUserDefined.HasFlag(InteropAttributeMember.StringMarshallingCustomType)) + && baseAttrInfo != attrInfo) { stringMarshallingDiagnostic = Diagnostic.Create( GeneratorDiagnostics.InvalidStringMarshallingMismatchBetweenBaseAndDerived, diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratedComInterfaceAttributeData.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratedComInterfaceAttributeData.cs index bb261b2b902c3e..f8c42b2c978529 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratedComInterfaceAttributeData.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratedComInterfaceAttributeData.cs @@ -55,6 +55,7 @@ public static GeneratedComInterfaceCompilationData GetAttributeDataFromInterface Debug.Assert(found); return GetDataFromAttribute(attr); } + public static GeneratedComInterfaceCompilationData GetDataFromAttribute(AttributeData attr) { Debug.Assert(attr.AttributeClass.ToDisplayString() == TypeNames.GeneratedComInterfaceAttribute); @@ -63,7 +64,5 @@ public static GeneratedComInterfaceCompilationData GetDataFromAttribute(Attribut generatedComInterfaceAttributeData = generatedComInterfaceAttributeData.WithValuesFromNamedArguments(args); return generatedComInterfaceAttributeData; } - } - } diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx index 45642c347adf1b..c3a64e8fe595a5 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx @@ -1,17 +1,17 @@  - @@ -256,7 +256,7 @@ The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface. - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. COM interface {0} inherits from {1}, which has errors. ComInterfaceGenerator will not generate source for {0}. @@ -267,4 +267,4 @@ The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} - + \ No newline at end of file diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf index 7d4ac762f809d7..60c449946a9abd 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf @@ -23,8 +23,8 @@ - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf index 818790d3c6f622..37d2dcec214ca4 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf @@ -23,8 +23,8 @@ - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf index 92ce9c3d51fbbb..c0acddd6c5e038 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf @@ -23,8 +23,8 @@ - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf index 7ea55be1093315..5cee651d6d3c04 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf @@ -23,8 +23,8 @@ - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf index 370a8c0616863c..9ca95c2440ce69 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf @@ -23,8 +23,8 @@ - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf index 2cf37ff3533c70..2c52348607e4c8 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf @@ -23,8 +23,8 @@ - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf index 9490a4429bf0dd..746b359f927f0b 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf @@ -23,8 +23,8 @@ - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf index 9b6899ac85b184..3abf92593251dc 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf @@ -23,8 +23,8 @@ - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf index 9ffcd92c863f6f..1c7ad712767b03 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf @@ -23,8 +23,8 @@ - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf index 087040aa5dc0e4..5d3f4071dcef3f 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf @@ -23,8 +23,8 @@ - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf index 34e1e5ec40695b..5c0a4f05e8f92a 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf @@ -23,8 +23,8 @@ - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf index eff12f98103c1c..85ecd79e4afec3 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf @@ -23,8 +23,8 @@ - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf index d039f2d9ec2ff3..d12ce1762b55a8 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf @@ -23,8 +23,8 @@ - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. - COM interface source generation requires all base interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. + COM interface source generation requires all base COM interfaces to be valid interfaces. Fix any issues on the base interface to resolve this diagnostic. diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs index c54c0fc2cb9f74..dfdc84a82dde2b 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs @@ -307,7 +307,7 @@ internal partial interface {|#{{i}}:IStringMarshalling{{i}}|} {{(i > 0 ? $": ISt using System.Runtime.InteropServices; using System.Runtime.InteropServices.Marshalling; - namespace SharedTypes.ComInterfaces + namespace Test { {{string.Join("\n\n", declarations)}} } diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs index 9e545ea0f7fe0a..9feaf81ab2a594 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs @@ -18,6 +18,7 @@ using VerifyComInterfaceGenerator = Microsoft.Interop.UnitTests.Verifiers.CSharpSourceGeneratorVerifier; using StringMarshalling = System.Runtime.InteropServices.StringMarshalling; +using System.Runtime.InteropServices.Marshalling; namespace ComInterfaceGenerator.Unit.Tests { @@ -96,26 +97,30 @@ public static IEnumerable InvalidUnmanagedToManagedCodeSnippetsToCompi public static IEnumerable StringMarshallingCodeSnippets(GeneratorKind generator) { + const string CustomStringMarshallingWithNoCustomTypeMessage = @"'StringMarshallingCustomType' must be specified when 'StringMarshalling' is set to 'StringMarshalling.Custom'."; + const string CustomTypeSpecifiedWithNoStringMarshallingCustom = @"'StringMarshalling' should be set to 'StringMarshalling.Custom' when 'StringMarshallingCustomType' is specified."; + const string StringMarshallingMustMatchBase = "The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' must match the base COM interface."; + CodeSnippets codeSnippets = new(GetAttributeProvider(generator)); (StringMarshalling, Type?) utf8Marshalling = (StringMarshalling.Utf8, null); (StringMarshalling, Type?) utf16Marshalling = (StringMarshalling.Utf16, null); (StringMarshalling, Type?) customUtf16Marshalling = (StringMarshalling.Custom, typeof(Utf16StringMarshaller)); (StringMarshalling, Type?) customWithNoType = (StringMarshalling.Custom, null); - (StringMarshalling, Type?) utf8WithType = (StringMarshalling.Custom, null); + (StringMarshalling, Type?) utf8WithType = (StringMarshalling.Utf8, typeof(Utf16StringMarshaller)); DiagnosticResult[] emptyDiagnostics = new DiagnosticResult[] { }; - // Custom with + // StringMarshalling.Custom / StringMarshallingCustomType invalid yield return new object[] { ID(), codeSnippets.DerivedWithStringMarshalling(customWithNoType), - new DiagnosticResult[] { new DiagnosticResult(GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface).WithLocation(0) } + new DiagnosticResult[] { new DiagnosticResult(GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface).WithLocation(0).WithArguments("Test.IStringMarshalling0", CustomStringMarshallingWithNoCustomTypeMessage) } }; yield return new object[] { ID(), codeSnippets.DerivedWithStringMarshalling(utf8WithType), - new DiagnosticResult[] { new DiagnosticResult(GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface).WithLocation(0) } + new DiagnosticResult[] { new DiagnosticResult(GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface).WithLocation(0).WithArguments("Test.IStringMarshalling0", CustomTypeSpecifiedWithNoStringMarshallingCustom) } }; // Inheritance no diagnostic @@ -224,13 +229,63 @@ public static IEnumerable StringMarshallingCodeSnippets(GeneratorKind MismatchesWithLocations(1, 2) }; + // Base has no StringMarshalling and Derived does is okay + string source = $$""" + using System; + using System.Runtime.InteropServices; + using System.Runtime.InteropServices.Marshalling; + namespace Test + { + [GeneratedComInterface] + [Guid("0E7204B5-4B61-4E06-B872-82BA652F2ECA")] + internal partial interface INoStringMarshalling + { + public int GetInt(); + public void SetInt(int value); + } + [GeneratedComInterface(StringMarshalling = StringMarshalling.Utf8)] + [Guid("0E7204B5-4B61-5E06-B872-82BA652F2ECA")] + internal partial interface IStringMarshalling : INoStringMarshalling + { + public string GetString(); + public void SetString(string value); + } + } + """; + yield return new object[] { ID(), source, emptyDiagnostics }; + // Compilation can't find MarshalAs or MarshalUsing + //source = $$""" + // using System; + // using System.Runtime.InteropServices; + // using System.Runtime.InteropServices.Marshalling; + // namespace Test + // { + // [GeneratedComInterface] + // [Guid("0E7204B5-4B61-4E06-B872-82BA652F2ECA")] + // internal partial interface INoStringMarshalling + // { + // [return: MarshalUsing(typeof(Utf8StringMarshaller)] + // public string GetString(); + // public void SetString([MarshalUsing(typeof(Utf8StringMarshaller))] string value); + // } + // [GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)] + // [Guid("0E7204B5-4B61-5E06-B872-82BA652F2ECA")] + // internal partial interface IStringMarshalling : INoStringMarshalling + // { + // public string GetString2(); + // public void SetString2(string value); + // } + // } + // """; + //yield return new object[] { ID(), source, emptyDiagnostics }; DiagnosticResult[] MismatchesWithLocations(params int[] locations) { return locations .Select(i => new DiagnosticResult(GeneratorDiagnostics.InvalidStringMarshallingMismatchBetweenBaseAndDerived) - .WithLocation(i)) + .WithLocation(i) + .WithArguments($"Test.IStringMarshalling{i}", StringMarshallingMustMatchBase)) .ToArray(); } DiagnosticResult[] BaseCannotBeGeneratedWithLocations(params int[] locations) @@ -239,7 +294,7 @@ DiagnosticResult[] BaseCannotBeGeneratedWithLocations(params int[] locations) .Select(i => new DiagnosticResult(GeneratorDiagnostics.BaseInterfaceIsNotGenerated) .WithLocation(i) - .WithArguments($"StringMarshalling{i}", $"StringMarshalling{i-1}", )) + .WithArguments($"Test.IStringMarshalling{i}", $"Test.IStringMarshalling{i - 1}")) .ToArray(); } } From f78d1ecaa6034431b889c15c17a72455c9c314a8 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Fri, 19 May 2023 16:06:55 -0700 Subject: [PATCH 09/13] Update failing if base fails logic --- .../ComInterfaceContext.cs | 43 +++++++++++-------- .../CompileFails.cs | 8 ++++ 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceContext.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceContext.cs index 192d03b63cde07..94a8fb6285aa13 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceContext.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceContext.cs @@ -4,8 +4,10 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Diagnostics; using System.Threading; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; namespace Microsoft.Interop { @@ -22,7 +24,7 @@ internal sealed record ComInterfaceContext(ComInterfaceInfo Info, ComInterfaceCo { nameToInterfaceInfoMap.Add(iface.ThisInterfaceKey, iface); } - Dictionary nameToContextMap = new(); + Dictionary nameToContextCache = new(); foreach (var iface in data) { @@ -32,34 +34,40 @@ internal sealed record ComInterfaceContext(ComInterfaceInfo Info, ComInterfaceCo (ComInterfaceContext? Context, Diagnostic? Diagnostic) AddContext(ComInterfaceInfo iface) { - if (nameToContextMap.TryGetValue(iface.ThisInterfaceKey, out var cachedValue)) + if (nameToContextCache.TryGetValue(iface.ThisInterfaceKey, out var cachedValue)) { - return (cachedValue, null); + return cachedValue; } if (iface.BaseInterfaceKey is null) { var baselessCtx = new ComInterfaceContext(iface, null); - nameToContextMap[iface.ThisInterfaceKey] = baselessCtx; + nameToContextCache[iface.ThisInterfaceKey] = (baselessCtx, null); return (baselessCtx, null); } - if (!nameToContextMap.TryGetValue(iface.BaseInterfaceKey, out var baseContext)) + if ( + // Cached base info has a diagnostic - failure + (nameToContextCache.TryGetValue(iface.BaseInterfaceKey, out var basePair) && basePair.Diagnostic is not null) + // Cannot find base ComInterfaceInfo - failure (failed ComInterfaceInfo creation) + || !nameToInterfaceInfoMap.TryGetValue(iface.BaseInterfaceKey, out var baseInfo) + // Newly calculated base context pair has a diagnostic - failure + || (AddContext(baseInfo) is { } baseReturnPair && baseReturnPair.Diagnostic is not null)) { - if(!nameToInterfaceInfoMap.TryGetValue(iface.BaseInterfaceKey, out var baseInfo)) - { - //Diagnostic that there is an issue with the base, so the interface cannot be - return (null, - Diagnostic.Create( - GeneratorDiagnostics.BaseInterfaceIsNotGenerated, - iface.DiagnosticLocation.AsLocation(), iface.ThisInterfaceKey, iface.BaseInterfaceKey)); - - } - (baseContext, var baseDiag) = AddContext(baseInfo); + // The base has failed generation at some point, so this interface cannot be generated + (ComInterfaceContext, Diagnostic?) diagnosticPair = (null, + Diagnostic.Create( + GeneratorDiagnostics.BaseInterfaceIsNotGenerated, + iface.DiagnosticLocation.AsLocation(), iface.ThisInterfaceKey, iface.BaseInterfaceKey)); + nameToContextCache[iface.ThisInterfaceKey] = diagnosticPair; + return diagnosticPair; } + var baseContext = basePair.Context ?? baseReturnPair.Context; + Debug.Assert(baseContext != null); var ctx = new ComInterfaceContext(iface, baseContext); - nameToContextMap[iface.ThisInterfaceKey] = ctx; - return (ctx, null); + (ComInterfaceContext, Diagnostic?) contextPair = (ctx, null); + nameToContextCache[iface.ThisInterfaceKey] = contextPair; + return contextPair; } } @@ -70,6 +78,5 @@ internal ComInterfaceContext GetTopLevelBase() currBase = currBase.Base; return currBase; } - } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs index 9feaf81ab2a594..c328f18d218204 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs @@ -279,6 +279,14 @@ internal partial interface IStringMarshalling : INoStringMarshalling // """; //yield return new object[] { ID(), source, emptyDiagnostics }; + // Base many levels up fails, all inheriting fail + yield return new object[] + { + ID(), + codeSnippets.DerivedWithStringMarshalling(customWithNoType, customUtf16Marshalling, customUtf16Marshalling, customUtf16Marshalling, customUtf16Marshalling, customUtf16Marshalling), + new DiagnosticResult[] {new DiagnosticResult(GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface).WithLocation(0).WithArguments("Test.IStringMarshalling0", CustomStringMarshallingWithNoCustomTypeMessage) }.Concat(MismatchesWithLocations(1)).Concat(BaseCannotBeGeneratedWithLocations(2, 3, 4, 5)).ToArray() + }; + DiagnosticResult[] MismatchesWithLocations(params int[] locations) { return locations From 036c6c0a739075d320df59ffa5b18e85641b58eb Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Fri, 19 May 2023 16:15:02 -0700 Subject: [PATCH 10/13] formatting and comment for LocationInfo --- .../gen/ComInterfaceGenerator/ComInterfaceInfo.cs | 13 +++++++------ .../gen/ComInterfaceGenerator/LocationInfo.cs | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs index cfcf50eb49ed6c..1c5c523086343c 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs @@ -63,15 +63,17 @@ public static (ComInterfaceInfo? Info, Diagnostic? Diagnostic) From(INamedTypeSy if (!StringMarshallingIsValid(symbol, syntax, baseSymbol, out Diagnostic? stringMarshallingDiagnostic)) return (null, stringMarshallingDiagnostic); - return (new ComInterfaceInfo( + return ( + new ComInterfaceInfo( ManagedTypeInfo.CreateTypeInfoForTypeSymbol(symbol), - symbol.ToDisplayString(), - baseSymbol?.ToDisplayString(), + symbol.ToDisplayString(), + baseSymbol?.ToDisplayString(), syntax, new ContainingSyntaxContext(syntax), new ContainingSyntax(syntax.Modifiers, syntax.Kind(), syntax.Identifier, syntax.TypeParameterList), - guid ?? Guid.Empty, - LocationInfo.From(symbol)), null); + guid ?? Guid.Empty, + LocationInfo.From(symbol)), + null); } private static bool StringMarshallingIsValid(INamedTypeSymbol symbol, InterfaceDeclarationSyntax syntax, INamedTypeSymbol? baseSymbol, [NotNullWhen(false)] out Diagnostic? stringMarshallingDiagnostic) @@ -116,7 +118,6 @@ private static bool StringMarshallingIsValid(INamedTypeSymbol symbol, InterfaceD } stringMarshallingDiagnostic = null; return true; - } /// diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/LocationInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/LocationInfo.cs index 473d5089f1c738..982e1ca75bc6ab 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/LocationInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/LocationInfo.cs @@ -6,6 +6,9 @@ namespace Microsoft.Interop { + /// + /// Contains data required to reconstruct a without keeping any symbols or references to a + /// internal sealed record LocationInfo( LinePositionSpan LinePositionSpan, string FilePath, From 60aaa59565f6ef94672ba7b6d2186a1ac7285d53 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Fri, 19 May 2023 16:42:35 -0700 Subject: [PATCH 11/13] format again --- .../gen/ComInterfaceGenerator/ComInterfaceInfo.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs index 1c5c523086343c..533eb8c54bb8eb 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs @@ -102,7 +102,6 @@ private static bool StringMarshallingIsValid(INamedTypeSymbol symbol, InterfaceD } if (baseSymbol is not null) { - var baseAttrInfo = GeneratedComInterfaceData.From(GeneratedComInterfaceCompilationData.GetAttributeDataFromInterfaceSymbol(baseSymbol)); // The base can be undefined string marshalling if ((baseAttrInfo.IsUserDefined.HasFlag(InteropAttributeMember.StringMarshalling) || baseAttrInfo.IsUserDefined.HasFlag(InteropAttributeMember.StringMarshallingCustomType)) From 0a2851071d480764e9819bed930f518a920200a6 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Mon, 22 May 2023 11:39:10 -0700 Subject: [PATCH 12/13] Make prop method --- .../tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs index a3f15bfd80e10f..bb2cd4aa8efdb9 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs @@ -315,7 +315,7 @@ namespace Test } public string ComInterfaceParameters => BasicParametersAndModifiers("IComInterface2") + $$""" - {{GeneratedComInterface}} + {{GeneratedComInterface()}} partial interface IComInterface2 { void Method2(); From 87d6169118da2ec871a62214481e65035db23c12 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Mon, 22 May 2023 15:05:22 -0700 Subject: [PATCH 13/13] formatting --- .../ComInterfaceGenerator/ComMethodContext.cs | 1 + .../CodeSnippets.cs | 6 +- .../CompileFails.cs | 77 ++++++++++++------- 3 files changed, 52 insertions(+), 32 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComMethodContext.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComMethodContext.cs index daf7c149adf922..f4aa8979a5a1fa 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComMethodContext.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComMethodContext.cs @@ -109,6 +109,7 @@ private MethodDeclarationSyntax CreateUnreachableExceptionStub() .WithAttributeLists(List()) .WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier( ParseName(OriginalDeclaringInterface.Info.Type.FullTypeName))) + .WithParameterList(ParameterList(SeparatedList(GenerationContext.SignatureContext.StubParameters))) .WithExpressionBody(ArrowExpressionClause( ThrowExpression( ObjectCreationExpression( diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs index bb2cd4aa8efdb9..f6f54511e22d4d 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs @@ -290,11 +290,11 @@ public string DerivedWithStringMarshalling(params { List declarations = new(); int i = 0; - foreach(var args in attributeArguments) + foreach (var args in attributeArguments) { declarations.Add($$""" {{GeneratedComInterface(args.StringMarshalling, args.StringMarshallingCustomType)}} - internal partial interface {|#{{i}}:IStringMarshalling{{i}}|} {{(i > 0 ? $": IStringMarshalling{i-1}" : "")}} + internal partial interface {|#{{i}}:IStringMarshalling{{i}}|} {{(i > 0 ? $": IStringMarshalling{i - 1}" : "")}} { public string GetString{{i}}(); public void SetString{{i}}(string value); @@ -302,7 +302,7 @@ internal partial interface {|#{{i}}:IStringMarshalling{{i}}|} {{(i > 0 ? $": ISt """); i++; } - return $$""" + return $$""" using System; using System.Runtime.InteropServices; using System.Runtime.InteropServices.Marshalling; diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs index c328f18d218204..ee1c28017c555f 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CompileFails.cs @@ -114,13 +114,23 @@ public static IEnumerable StringMarshallingCodeSnippets(GeneratorKind { ID(), codeSnippets.DerivedWithStringMarshalling(customWithNoType), - new DiagnosticResult[] { new DiagnosticResult(GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface).WithLocation(0).WithArguments("Test.IStringMarshalling0", CustomStringMarshallingWithNoCustomTypeMessage) } + new DiagnosticResult[] + { + VerifyComInterfaceGenerator.Diagnostic(GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface) + .WithLocation(0) + .WithArguments("Test.IStringMarshalling0", CustomStringMarshallingWithNoCustomTypeMessage) + } }; yield return new object[] { ID(), codeSnippets.DerivedWithStringMarshalling(utf8WithType), - new DiagnosticResult[] { new DiagnosticResult(GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface).WithLocation(0).WithArguments("Test.IStringMarshalling0", CustomTypeSpecifiedWithNoStringMarshallingCustom) } + new DiagnosticResult[] + { + VerifyComInterfaceGenerator.Diagnostic(GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface) + .WithLocation(0) + .WithArguments("Test.IStringMarshalling0", CustomTypeSpecifiedWithNoStringMarshallingCustom) + } }; // Inheritance no diagnostic @@ -253,38 +263,46 @@ internal partial interface IStringMarshalling : INoStringMarshalling } """; yield return new object[] { ID(), source, emptyDiagnostics }; - // Compilation can't find MarshalAs or MarshalUsing - //source = $$""" - // using System; - // using System.Runtime.InteropServices; - // using System.Runtime.InteropServices.Marshalling; - // namespace Test - // { - // [GeneratedComInterface] - // [Guid("0E7204B5-4B61-4E06-B872-82BA652F2ECA")] - // internal partial interface INoStringMarshalling - // { - // [return: MarshalUsing(typeof(Utf8StringMarshaller)] - // public string GetString(); - // public void SetString([MarshalUsing(typeof(Utf8StringMarshaller))] string value); - // } - // [GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)] - // [Guid("0E7204B5-4B61-5E06-B872-82BA652F2ECA")] - // internal partial interface IStringMarshalling : INoStringMarshalling - // { - // public string GetString2(); - // public void SetString2(string value); - // } - // } - // """; - //yield return new object[] { ID(), source, emptyDiagnostics }; + + source = $$""" + using System; + using System.Runtime.InteropServices; + using System.Runtime.InteropServices.Marshalling; + namespace Test + { + [GeneratedComInterface] + [Guid("0E7204B5-4B61-4E06-B872-82BA652F2ECA")] + internal partial interface INoStringMarshalling + { + [return: MarshalUsing(typeof(Utf8StringMarshaller))] + public string GetString(); + public void SetString([MarshalUsing(typeof(Utf8StringMarshaller))] string value); + } + [GeneratedComInterface(StringMarshalling = StringMarshalling.Utf16)] + [Guid("0E7204B5-4B61-5E06-B872-82BA652F2ECA")] + internal partial interface IStringMarshalling : INoStringMarshalling + { + public string GetString2(); + public void SetString2(string value); + } + } + """; + yield return new object[] { ID(), source, emptyDiagnostics }; // Base many levels up fails, all inheriting fail yield return new object[] { ID(), codeSnippets.DerivedWithStringMarshalling(customWithNoType, customUtf16Marshalling, customUtf16Marshalling, customUtf16Marshalling, customUtf16Marshalling, customUtf16Marshalling), - new DiagnosticResult[] {new DiagnosticResult(GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface).WithLocation(0).WithArguments("Test.IStringMarshalling0", CustomStringMarshallingWithNoCustomTypeMessage) }.Concat(MismatchesWithLocations(1)).Concat(BaseCannotBeGeneratedWithLocations(2, 3, 4, 5)).ToArray() + new DiagnosticResult[] + { + VerifyComInterfaceGenerator.Diagnostic(GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnInterface) + .WithLocation(0) + .WithArguments("Test.IStringMarshalling0", CustomStringMarshallingWithNoCustomTypeMessage) + } + .Concat(MismatchesWithLocations(1)) + .Concat(BaseCannotBeGeneratedWithLocations(2, 3, 4, 5)) + .ToArray() }; DiagnosticResult[] MismatchesWithLocations(params int[] locations) @@ -294,8 +312,9 @@ DiagnosticResult[] MismatchesWithLocations(params int[] locations) new DiagnosticResult(GeneratorDiagnostics.InvalidStringMarshallingMismatchBetweenBaseAndDerived) .WithLocation(i) .WithArguments($"Test.IStringMarshalling{i}", StringMarshallingMustMatchBase)) - .ToArray(); + .ToArray(); } + DiagnosticResult[] BaseCannotBeGeneratedWithLocations(params int[] locations) { return locations