From 5c73f79f804325d56f82b8710b26533d172ae28c Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Wed, 3 Nov 2021 14:03:04 -0700 Subject: [PATCH] Remove BestFitMapping, CallingConvention, and ThrowOnUnmappableChar from GeneratedDllImportAttribute --- .../Advapi32/Interop.LookupPrivilegeValue.cs | 5 -- .../Advapi32/Interop.RegCreateKeyEx.cs | 5 -- .../Advapi32/Interop.RegDeleteKeyEx.cs | 5 -- .../Advapi32/Interop.RegDeleteValue.cs | 5 -- .../Windows/Advapi32/Interop.RegFlushKey.cs | 8 +-- .../Windows/Advapi32/Interop.RegOpenKeyEx.cs | 11 ---- .../Windows/Advapi32/Interop.RegSetValueEx.cs | 25 --------- .../Kernel32/Interop.GetFullPathNameW.cs | 5 -- .../Kernel32/Interop.GetLongPathNameW.cs | 5 -- .../GeneratedDllImportAttribute.cs | 4 -- .../src/Microsoft.Win32.Registry.csproj | 1 + .../Microsoft.Win32.Registry.Tests.csproj | 2 + .../DllImportGenerator/DllImportGenerator.cs | 56 +------------------ .../GeneratedDllImportData.cs | 16 ++---- .../CodeSnippets.cs | 24 +------- .../CompileFails.cs | 4 -- .../DllImportGenerator.UnitTests/Compiles.cs | 4 +- 17 files changed, 14 insertions(+), 171 deletions(-) diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LookupPrivilegeValue.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LookupPrivilegeValue.cs index c4276f4af72ee..7781cf4b6cf2a 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LookupPrivilegeValue.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LookupPrivilegeValue.cs @@ -7,13 +7,8 @@ internal static partial class Interop { internal static partial class Advapi32 { -#if DLLIMPORTGENERATOR_ENABLED [GeneratedDllImport(Libraries.Advapi32, EntryPoint = "LookupPrivilegeValueW", CharSet = CharSet.Unicode, SetLastError = true)] internal static partial bool LookupPrivilegeValue( -#else - [DllImport(Libraries.Advapi32, EntryPoint = "LookupPrivilegeValueW", CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)] - internal static extern bool LookupPrivilegeValue( -#endif [MarshalAs(UnmanagedType.LPTStr)] string? lpSystemName, [MarshalAs(UnmanagedType.LPTStr)] string lpName, out LUID lpLuid); internal const string SeDebugPrivilege = "SeDebugPrivilege"; diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegCreateKeyEx.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegCreateKeyEx.cs index 44671dd679c0c..f376bc9ec5463 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegCreateKeyEx.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegCreateKeyEx.cs @@ -14,13 +14,8 @@ internal static partial class Advapi32 { // Note: RegCreateKeyEx won't set the last error on failure - it returns // an error code if it fails. -#if DLLIMPORTGENERATOR_ENABLED [GeneratedDllImport(Libraries.Advapi32, EntryPoint = "RegCreateKeyExW", CharSet = CharSet.Unicode, ExactSpelling = true)] internal static partial int RegCreateKeyEx( -#else - [DllImport(Libraries.Advapi32, EntryPoint = "RegCreateKeyExW", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true)] - internal static extern int RegCreateKeyEx( -#endif SafeRegistryHandle hKey, string lpSubKey, int Reserved, diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegDeleteKeyEx.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegDeleteKeyEx.cs index d7a5752143430..b51199269cfed 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegDeleteKeyEx.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegDeleteKeyEx.cs @@ -12,13 +12,8 @@ internal static partial class Interop { internal static partial class Advapi32 { -#if DLLIMPORTGENERATOR_ENABLED [GeneratedDllImport(Libraries.Advapi32, EntryPoint = "RegDeleteKeyExW", CharSet = CharSet.Unicode, ExactSpelling = true)] internal static partial int RegDeleteKeyEx( -#else - [DllImport(Libraries.Advapi32, EntryPoint = "RegDeleteKeyExW", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true)] - internal static extern int RegDeleteKeyEx( -#endif SafeRegistryHandle hKey, string lpSubKey, int samDesired, diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegDeleteValue.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegDeleteValue.cs index 50824a4ede142..f5a8e05cd61a7 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegDeleteValue.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegDeleteValue.cs @@ -12,13 +12,8 @@ internal static partial class Interop { internal static partial class Advapi32 { -#if DLLIMPORTGENERATOR_ENABLED [GeneratedDllImport(Libraries.Advapi32, EntryPoint = "RegDeleteValueW", CharSet = CharSet.Unicode, ExactSpelling = true)] internal static partial int RegDeleteValue( -#else - [DllImport(Libraries.Advapi32, EntryPoint = "RegDeleteValueW", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true)] - internal static extern int RegDeleteValue( -#endif SafeRegistryHandle hKey, string? lpValueName); } diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegFlushKey.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegFlushKey.cs index 5bb1046bee338..ce43f1ac64031 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegFlushKey.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegFlushKey.cs @@ -12,13 +12,7 @@ internal static partial class Interop { internal static partial class Advapi32 { -#if DLLIMPORTGENERATOR_ENABLED [GeneratedDllImport(Libraries.Advapi32)] - internal static partial int RegFlushKey( -#else - [DllImport(Libraries.Advapi32)] - internal static extern int RegFlushKey( -#endif - SafeRegistryHandle hKey); + internal static partial int RegFlushKey(SafeRegistryHandle hKey); } } diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegOpenKeyEx.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegOpenKeyEx.cs index 4ffba18c4a2c6..9f9af2c268b7e 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegOpenKeyEx.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegOpenKeyEx.cs @@ -13,27 +13,16 @@ internal static partial class Interop { internal static partial class Advapi32 { -#if DLLIMPORTGENERATOR_ENABLED [GeneratedDllImport(Libraries.Advapi32, EntryPoint = "RegOpenKeyExW", CharSet = CharSet.Unicode, ExactSpelling = true)] internal static partial int RegOpenKeyEx( -#else - [DllImport(Libraries.Advapi32, EntryPoint = "RegOpenKeyExW", CharSet = CharSet.Unicode, ExactSpelling = true)] - internal static extern int RegOpenKeyEx( -#endif SafeRegistryHandle hKey, string? lpSubKey, int ulOptions, int samDesired, out SafeRegistryHandle hkResult); - -#if DLLIMPORTGENERATOR_ENABLED [GeneratedDllImport(Libraries.Advapi32, EntryPoint = "RegOpenKeyExW", CharSet = CharSet.Unicode, ExactSpelling = true)] internal static partial int RegOpenKeyEx( -#else - [DllImport(Libraries.Advapi32, EntryPoint = "RegOpenKeyExW", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true)] - internal static extern int RegOpenKeyEx( -#endif IntPtr hKey, string? lpSubKey, int ulOptions, diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegSetValueEx.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegSetValueEx.cs index 8bb444aa563f3..5e2e9221f2ead 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegSetValueEx.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.RegSetValueEx.cs @@ -12,13 +12,8 @@ internal static partial class Interop { internal static partial class Advapi32 { -#if DLLIMPORTGENERATOR_ENABLED [GeneratedDllImport(Libraries.Advapi32, EntryPoint = "RegSetValueExW", CharSet = CharSet.Unicode, ExactSpelling = true)] internal static partial int RegSetValueEx( -#else - [DllImport(Libraries.Advapi32, EntryPoint = "RegSetValueExW", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true)] - internal static extern int RegSetValueEx( -#endif SafeRegistryHandle hKey, string? lpValueName, int Reserved, @@ -26,13 +21,8 @@ internal static extern int RegSetValueEx( byte[]? lpData, int cbData); -#if DLLIMPORTGENERATOR_ENABLED [GeneratedDllImport(Libraries.Advapi32, EntryPoint = "RegSetValueExW", CharSet = CharSet.Unicode, ExactSpelling = true)] internal static partial int RegSetValueEx( -#else - [DllImport(Libraries.Advapi32, EntryPoint = "RegSetValueExW", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true)] - internal static extern int RegSetValueEx( -#endif SafeRegistryHandle hKey, string? lpValueName, int Reserved, @@ -40,13 +30,8 @@ internal static extern int RegSetValueEx( char[]? lpData, int cbData); -#if DLLIMPORTGENERATOR_ENABLED [GeneratedDllImport(Libraries.Advapi32, EntryPoint = "RegSetValueExW", CharSet = CharSet.Unicode, ExactSpelling = true)] internal static partial int RegSetValueEx( -#else - [DllImport(Libraries.Advapi32, EntryPoint = "RegSetValueExW", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true)] - internal static extern int RegSetValueEx( -#endif SafeRegistryHandle hKey, string? lpValueName, int Reserved, @@ -54,13 +39,8 @@ internal static extern int RegSetValueEx( ref int lpData, int cbData); -#if DLLIMPORTGENERATOR_ENABLED [GeneratedDllImport(Libraries.Advapi32, EntryPoint = "RegSetValueExW", CharSet = CharSet.Unicode, ExactSpelling = true)] internal static partial int RegSetValueEx( -#else - [DllImport(Libraries.Advapi32, EntryPoint = "RegSetValueExW", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true)] - internal static extern int RegSetValueEx( -#endif SafeRegistryHandle hKey, string? lpValueName, int Reserved, @@ -68,13 +48,8 @@ internal static extern int RegSetValueEx( ref long lpData, int cbData); -#if DLLIMPORTGENERATOR_ENABLED [GeneratedDllImport(Libraries.Advapi32, EntryPoint = "RegSetValueExW", CharSet = CharSet.Unicode, ExactSpelling = true)] internal static partial int RegSetValueEx( -#else - [DllImport(Libraries.Advapi32, EntryPoint = "RegSetValueExW", BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true)] - internal static extern int RegSetValueEx( -#endif SafeRegistryHandle hKey, string? lpValueName, int Reserved, diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetFullPathNameW.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetFullPathNameW.cs index 191cfd64591d1..69b6875d47a3f 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetFullPathNameW.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetFullPathNameW.cs @@ -11,13 +11,8 @@ internal static partial class Kernel32 /// /// WARNING: This method does not implicitly handle long paths. Use GetFullPathName or PathHelper. /// -#if DLLIMPORTGENERATOR_ENABLED [GeneratedDllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)] internal static partial uint GetFullPathNameW( -#else - [DllImport(Libraries.Kernel32, BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)] - internal static extern uint GetFullPathNameW( -#endif ref char lpFileName, uint nBufferLength, ref char lpBuffer, diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetLongPathNameW.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetLongPathNameW.cs index 10d536df0964e..1556e3f2b29e1 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetLongPathNameW.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetLongPathNameW.cs @@ -10,13 +10,8 @@ internal static partial class Kernel32 /// /// WARNING: This method does not implicitly handle long paths. Use GetFullPath/PathHelper. /// -#if DLLIMPORTGENERATOR_ENABLED [GeneratedDllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)] internal static partial uint GetLongPathNameW( -#else - [DllImport(Libraries.Kernel32, BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)] - internal static extern uint GetLongPathNameW( -#endif ref char lpszShortPath, ref char lpszLongPath, uint cchBuffer); diff --git a/src/libraries/Common/src/System/Runtime/InteropServices/GeneratedDllImportAttribute.cs b/src/libraries/Common/src/System/Runtime/InteropServices/GeneratedDllImportAttribute.cs index e6ae47ac8fbfc..e64fae1c7ad80 100644 --- a/src/libraries/Common/src/System/Runtime/InteropServices/GeneratedDllImportAttribute.cs +++ b/src/libraries/Common/src/System/Runtime/InteropServices/GeneratedDllImportAttribute.cs @@ -5,7 +5,6 @@ // // Types in this file are used for generated p/invokes (docs/design/features/source-generator-pinvokes.md). -// See the DllImportGenerator experiment in https://github.com/dotnet/runtimelab. // namespace System.Runtime.InteropServices { @@ -20,14 +19,11 @@ namespace System.Runtime.InteropServices #endif sealed class GeneratedDllImportAttribute : Attribute { - public bool BestFitMapping { get; set; } - public CallingConvention CallingConvention { get; set; } public CharSet CharSet { get; set; } public string? EntryPoint { get; set; } public bool ExactSpelling { get; set; } public bool PreserveSig { get; set; } public bool SetLastError { get; set; } - public bool ThrowOnUnmappableChar { get; set; } public GeneratedDllImportAttribute(string dllName) { diff --git a/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj b/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj index 2c5fa34fc434d..8fbb8dd78854b 100644 --- a/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj +++ b/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj @@ -81,6 +81,7 @@ + diff --git a/src/libraries/Microsoft.Win32.Registry/tests/Microsoft.Win32.Registry.Tests.csproj b/src/libraries/Microsoft.Win32.Registry/tests/Microsoft.Win32.Registry.Tests.csproj index e88f97d0cb43c..97452ace1fcdc 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/Microsoft.Win32.Registry.Tests.csproj +++ b/src/libraries/Microsoft.Win32.Registry/tests/Microsoft.Win32.Registry.Tests.csproj @@ -2,6 +2,8 @@ $(DefineConstants);REGISTRY_ASSEMBLY $(NetCoreAppCurrent)-windows + true + true namedArg in attrData.NamedArguments) @@ -365,14 +362,6 @@ private static GeneratedDllImportData ProcessGeneratedDllImportAttribute(Attribu default: Debug.Fail($"An unknown member was found on {GeneratedDllImport}"); continue; - case nameof(GeneratedDllImportData.BestFitMapping): - userDefinedValues |= DllImportMember.BestFitMapping; - bestFitMapping = (bool)namedArg.Value.Value!; - break; - case nameof(GeneratedDllImportData.CallingConvention): - userDefinedValues |= DllImportMember.CallingConvention; - callingConvention = (CallingConvention)namedArg.Value.Value!; - break; case nameof(GeneratedDllImportData.CharSet): userDefinedValues |= DllImportMember.CharSet; charSet = (CharSet)namedArg.Value.Value!; @@ -393,24 +382,17 @@ private static GeneratedDllImportData ProcessGeneratedDllImportAttribute(Attribu userDefinedValues |= DllImportMember.SetLastError; setLastError = (bool)namedArg.Value.Value!; break; - case nameof(GeneratedDllImportData.ThrowOnUnmappableChar): - userDefinedValues |= DllImportMember.ThrowOnUnmappableChar; - throwOnUnmappableChar = (bool)namedArg.Value.Value!; - break; } } return new GeneratedDllImportData(attrData.ConstructorArguments[0].Value!.ToString()) { IsUserDefined = userDefinedValues, - BestFitMapping = bestFitMapping, - CallingConvention = callingConvention, CharSet = charSet, EntryPoint = entryPoint, ExactSpelling = exactSpelling, PreserveSig = preserveSig, SetLastError = setLastError, - ThrowOnUnmappableChar = throwOnUnmappableChar }; } @@ -452,31 +434,16 @@ private static IncrementalStubGenerationContext CalculateStubInformation(IMethod // Process the GeneratedDllImport attribute GeneratedDllImportData stubDllImportData = ProcessGeneratedDllImportAttribute(generatedDllImportAttr!); - if (stubDllImportData.IsUserDefined.HasFlag(DllImportMember.BestFitMapping)) - { - generatorDiagnostics.ReportConfigurationNotSupported(generatedDllImportAttr!, nameof(GeneratedDllImportData.BestFitMapping)); - } - - if (stubDllImportData.IsUserDefined.HasFlag(DllImportMember.ThrowOnUnmappableChar)) - { - generatorDiagnostics.ReportConfigurationNotSupported(generatedDllImportAttr!, nameof(GeneratedDllImportData.ThrowOnUnmappableChar)); - } - - if (stubDllImportData.IsUserDefined.HasFlag(DllImportMember.CallingConvention)) - { - generatorDiagnostics.ReportConfigurationNotSupported(generatedDllImportAttr!, nameof(GeneratedDllImportData.CallingConvention)); - } - if (lcidConversionAttr != null) { // Using LCIDConversion with GeneratedDllImport is not supported generatorDiagnostics.ReportConfigurationNotSupported(lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); } - List additionalAttributes = GenerateSyntaxForForwardedAttributes(suppressGCTransitionAttribute, unmanagedCallConvAttribute); // Create the stub. var dllImportStub = DllImportStubContext.Create(symbol, stubDllImportData, environment, generatorDiagnostics, ct); + List additionalAttributes = GenerateSyntaxForForwardedAttributes(suppressGCTransitionAttribute, unmanagedCallConvAttribute); return new IncrementalStubGenerationContext(environment, dllImportStub, additionalAttributes.ToImmutableArray(), stubDllImportData, generatorDiagnostics.Diagnostics.ToImmutableArray()); } @@ -602,18 +569,6 @@ private static AttributeSyntax CreateDllImportAttributeForTarget(GeneratedDllImp CreateStringExpressionSyntax(targetDllImportData.EntryPoint!)) }; - if (targetDllImportData.IsUserDefined.HasFlag(DllImportMember.BestFitMapping)) - { - NameEqualsSyntax name = NameEquals(nameof(DllImportAttribute.BestFitMapping)); - ExpressionSyntax value = CreateBoolExpressionSyntax(targetDllImportData.BestFitMapping); - newAttributeArgs.Add(AttributeArgument(name, null, value)); - } - if (targetDllImportData.IsUserDefined.HasFlag(DllImportMember.CallingConvention)) - { - NameEqualsSyntax name = NameEquals(nameof(DllImportAttribute.CallingConvention)); - ExpressionSyntax value = CreateEnumExpressionSyntax(targetDllImportData.CallingConvention); - newAttributeArgs.Add(AttributeArgument(name, null, value)); - } if (targetDllImportData.IsUserDefined.HasFlag(DllImportMember.CharSet)) { NameEqualsSyntax name = NameEquals(nameof(DllImportAttribute.CharSet)); @@ -638,12 +593,6 @@ private static AttributeSyntax CreateDllImportAttributeForTarget(GeneratedDllImp ExpressionSyntax value = CreateBoolExpressionSyntax(targetDllImportData.SetLastError); newAttributeArgs.Add(AttributeArgument(name, null, value)); } - if (targetDllImportData.IsUserDefined.HasFlag(DllImportMember.ThrowOnUnmappableChar)) - { - NameEqualsSyntax name = NameEquals(nameof(DllImportAttribute.ThrowOnUnmappableChar)); - ExpressionSyntax value = CreateBoolExpressionSyntax(targetDllImportData.ThrowOnUnmappableChar); - newAttributeArgs.Add(AttributeArgument(name, null, value)); - } // Create new attribute return Attribute( @@ -691,13 +640,10 @@ private static GeneratedDllImportData GetTargetDllImportDataFromStubData(Generat var targetDllImportData = new GeneratedDllImportData(dllImportData.ModuleName) { CharSet = dllImportData.CharSet, - BestFitMapping = dllImportData.BestFitMapping, - CallingConvention = dllImportData.CallingConvention, EntryPoint = dllImportData.EntryPoint, ExactSpelling = dllImportData.ExactSpelling, SetLastError = dllImportData.SetLastError, PreserveSig = dllImportData.PreserveSig, - ThrowOnUnmappableChar = dllImportData.ThrowOnUnmappableChar, IsUserDefined = dllImportData.IsUserDefined & membersToForward }; diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/GeneratedDllImportData.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/GeneratedDllImportData.cs index d3157782f488c..07d0ddeb1ab74 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/GeneratedDllImportData.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/GeneratedDllImportData.cs @@ -15,14 +15,11 @@ namespace Microsoft.Interop public enum DllImportMember { None = 0, - BestFitMapping = 1 << 0, - CallingConvention = 1 << 1, - CharSet = 1 << 2, - EntryPoint = 1 << 3, - ExactSpelling = 1 << 4, - PreserveSig = 1 << 5, - SetLastError = 1 << 6, - ThrowOnUnmappableChar = 1 << 7, + CharSet = 1 << 0, + EntryPoint = 1 << 1, + ExactSpelling = 1 << 2, + PreserveSig = 1 << 3, + SetLastError = 1 << 4, All = ~None } @@ -39,13 +36,10 @@ public sealed record GeneratedDllImportData(string ModuleName) /// Value set by the user on the original declaration. /// public DllImportMember IsUserDefined { get; init; } - public bool BestFitMapping { get; init; } - public CallingConvention CallingConvention { get; init; } public CharSet CharSet { get; init; } public string? EntryPoint { get; init; } public bool ExactSpelling { get; init; } public bool PreserveSig { get; init; } public bool SetLastError { get; init; } - public bool ThrowOnUnmappableChar { get; init; } } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CodeSnippets.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CodeSnippets.cs index ce3a00f98292e..42d3d9c49c8c0 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CodeSnippets.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CodeSnippets.cs @@ -184,29 +184,9 @@ partial class Test "; /// - /// Declaration with all DllImport named arguments. + /// Declaration with all GeneratedDllImport named arguments. /// - public static readonly string AllDllImportNamedArguments = @" -using System.Runtime.InteropServices; -partial class Test -{ - [GeneratedDllImport(""DoesNotExist"", - BestFitMapping = false, - CallingConvention = CallingConvention.Cdecl, - CharSet = CharSet.Unicode, - EntryPoint = ""UserDefinedEntryPoint"", - ExactSpelling = true, - PreserveSig = false, - SetLastError = true, - ThrowOnUnmappableChar = true)] - public static partial void Method(); -} -"; - - /// - /// Declaration with all supported DllImport named arguments. - /// - public static readonly string AllSupportedDllImportNamedArguments = @" + public static readonly string AllGeneratedDllImportNamedArguments = @" using System.Runtime.InteropServices; partial class Test { diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CompileFails.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CompileFails.cs index 954009db80d67..a69af4566275b 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CompileFails.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CompileFails.cs @@ -58,10 +58,6 @@ public static IEnumerable CodeSnippetsToCompile() yield return new object[] { CodeSnippets.ByValueParameterWithModifier("Out"), 1, 0 }; yield return new object[] { CodeSnippets.ByValueParameterWithModifier("In, Out"), 1, 0 }; - // Unsupported named arguments - // * BestFitMapping, ThrowOnUnmappableChar, CallingConvention - yield return new object[] { CodeSnippets.AllDllImportNamedArguments, 3, 0 }; - // LCIDConversion yield return new object[] { CodeSnippets.LCIDConversionAttribute, 1, 0 }; diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Compiles.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Compiles.cs index aee1904683418..09318ac99baca 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Compiles.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Compiles.cs @@ -24,7 +24,7 @@ public static IEnumerable CodeSnippetsToCompile() yield return new[] { CodeSnippets.NestedTypes }; yield return new[] { CodeSnippets.UnsafeContext }; yield return new[] { CodeSnippets.UserDefinedEntryPoint }; - yield return new[] { CodeSnippets.AllSupportedDllImportNamedArguments }; + yield return new[] { CodeSnippets.AllGeneratedDllImportNamedArguments }; yield return new[] { CodeSnippets.DefaultParameters }; yield return new[] { CodeSnippets.UseCSharpFeaturesForConstants }; @@ -399,7 +399,7 @@ public async Task ValidateSnippetsWithBlittableAutoForwarding(string source) public static IEnumerable SnippetsWithBlittableTypesButNonBlittableDataToCompile() { - yield return new[] { CodeSnippets.AllSupportedDllImportNamedArguments }; + yield return new[] { CodeSnippets.AllGeneratedDllImportNamedArguments }; yield return new[] { CodeSnippets.BasicParametersAndModifiers() }; yield return new[] { CodeSnippets.PreserveSigFalse() }; }