Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElinor Fung <elfung@microsoft.com>2022-01-07 01:10:02 +0300
committerGitHub <noreply@github.com>2022-01-07 01:10:02 +0300
commitb0685e16172d8c8b12977e0734e900bd60b42d8f (patch)
tree1ef2d8bef6861aeb5e4ecac5f37955383982d13c
parent98c53288ac775a66576366e21adb021b5f8eca0f (diff)
[DllImportGenerator] Remove DLLIMPORTGENERATOR_ENABLED define (#63464)
-rw-r--r--eng/generators.targets4
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ConvertToGeneratedDllImportFixer.cs70
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.Designer.cs29
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.resx9
-rw-r--r--src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/ConvertToGeneratedDllImportFixerTests.cs236
-rw-r--r--src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Verifiers/CSharpCodeFixVerifier.cs15
6 files changed, 59 insertions, 304 deletions
diff --git a/eng/generators.targets b/eng/generators.targets
index 4c32554b5e2..843842937ef 100644
--- a/eng/generators.targets
+++ b/eng/generators.targets
@@ -84,10 +84,6 @@
<DllImportGenerator_UseInternalUnsafeType>true</DllImportGenerator_UseInternalUnsafeType>
<DefineConstants>$(DefineConstants);DLLIMPORTGENERATOR_INTERNALUNSAFE</DefineConstants>
</PropertyGroup>
-
- <PropertyGroup>
- <DefineConstants>$(DefineConstants);DLLIMPORTGENERATOR_ENABLED</DefineConstants>
- </PropertyGroup>
</Target>
<Import Project="$(LibrariesProjectRoot)System.Runtime.InteropServices/gen/DllImportGenerator/Microsoft.Interop.DllImportGenerator.props" />
diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ConvertToGeneratedDllImportFixer.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ConvertToGeneratedDllImportFixer.cs
index c99f64fcc48..829d508a726 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ConvertToGeneratedDllImportFixer.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ConvertToGeneratedDllImportFixer.cs
@@ -26,8 +26,7 @@ namespace Microsoft.Interop.Analyzers
public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer;
- public const string NoPreprocessorDefinesKey = "ConvertToGeneratedDllImport";
- public const string WithPreprocessorDefinesKey = "ConvertToGeneratedDllImportPreprocessor";
+ private const string ConvertToGeneratedDllImportKey = "ConvertToGeneratedDllImport";
private static readonly string[] s_preferredAttributeArgumentOrder =
{
@@ -70,33 +69,18 @@ namespace Microsoft.Interop.Analyzers
if (!TryGetAttribute(methodSymbol, dllImportAttrType, out AttributeData? dllImportAttr))
return;
- // Register code fixes with two options for the fix - using preprocessor or not.
+ // Register code fix
context.RegisterCodeFix(
CodeAction.Create(
- Resources.ConvertToGeneratedDllImportNoPreprocessor,
+ Resources.ConvertToGeneratedDllImport,
cancelToken => ConvertToGeneratedDllImport(
context.Document,
methodSyntax,
methodSymbol,
dllImportAttr!,
generatedDllImportAttrType,
- usePreprocessorDefines: false,
cancelToken),
- equivalenceKey: NoPreprocessorDefinesKey),
- context.Diagnostics);
-
- context.RegisterCodeFix(
- CodeAction.Create(
- Resources.ConvertToGeneratedDllImportWithPreprocessor,
- cancelToken => ConvertToGeneratedDllImport(
- context.Document,
- methodSyntax,
- methodSymbol,
- dllImportAttr!,
- generatedDllImportAttrType,
- usePreprocessorDefines: true,
- cancelToken),
- equivalenceKey: WithPreprocessorDefinesKey),
+ equivalenceKey: ConvertToGeneratedDllImportKey),
context.Diagnostics);
}
@@ -106,7 +90,6 @@ namespace Microsoft.Interop.Analyzers
IMethodSymbol methodSymbol,
AttributeData dllImportAttr,
INamedTypeSymbol generatedDllImportAttrType,
- bool usePreprocessorDefines,
CancellationToken cancellationToken)
{
DocumentEditor editor = await DocumentEditor.CreateAsync(doc, cancellationToken).ConfigureAwait(false);
@@ -142,49 +125,8 @@ namespace Microsoft.Interop.Analyzers
.WithIsExtern(false)
.WithPartial(true));
- if (!usePreprocessorDefines)
- {
- // Replace the original method with the updated one
- editor.ReplaceNode(methodSyntax, generatedDeclaration);
- }
- else
- {
- // #if DLLIMPORTGENERATOR_ENABLED
- generatedDeclaration = generatedDeclaration.WithLeadingTrivia(
- generatedDeclaration.GetLeadingTrivia()
- .AddRange(new[] {
- SyntaxFactory.Trivia(SyntaxFactory.IfDirectiveTrivia(SyntaxFactory.IdentifierName("DLLIMPORTGENERATOR_ENABLED"), isActive: true, branchTaken: true, conditionValue: true)),
- SyntaxFactory.ElasticMarker
- }));
-
- // #else
- generatedDeclaration = generatedDeclaration.WithTrailingTrivia(
- generatedDeclaration.GetTrailingTrivia()
- .AddRange(new[] {
- SyntaxFactory.Trivia(SyntaxFactory.ElseDirectiveTrivia(isActive: false, branchTaken: false)),
- SyntaxFactory.ElasticMarker
- }));
-
- // Sort attribute arguments so that GeneratedDllImport and DllImport match
- MethodDeclarationSyntax updatedDeclaration = (MethodDeclarationSyntax)generator.ReplaceNode(methodSyntax, dllImportSyntax, SortDllImportAttributeArguments(dllImportSyntax, generator));
-
- // Remove existing leading trivia - it will be on the GeneratedDllImport method
- updatedDeclaration = updatedDeclaration.WithLeadingTrivia();
-
- // #endif
- updatedDeclaration = updatedDeclaration.WithTrailingTrivia(
- methodSyntax.GetTrailingTrivia()
- .AddRange(new[] {
- SyntaxFactory.Trivia(SyntaxFactory.EndIfDirectiveTrivia(isActive: true)),
- SyntaxFactory.ElasticMarker
- }));
-
- // Add the GeneratedDllImport method
- editor.InsertBefore(methodSyntax, generatedDeclaration);
-
- // Replace the original method with the updated DllImport method
- editor.ReplaceNode(methodSyntax, updatedDeclaration);
- }
+ // Replace the original method with the updated one
+ editor.ReplaceNode(methodSyntax, generatedDeclaration);
return editor.GetChangedDocument();
}
diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.Designer.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.Designer.cs
index 28352565c85..744f1b611be 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.Designer.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.Designer.cs
@@ -79,7 +79,7 @@ namespace Microsoft.Interop {
}
/// <summary>
- /// Looks up a localized string similar to When constructor taking a Span&lt;byte&gt; is specified on the native type, the type must also have a public integer constant named BufferSize to provide the size of the caller-allocated buffer..
+ /// Looks up a localized string similar to When a constructor taking a Span&lt;byte&gt; is specified on the native type, the type must also have a public integer constant named BufferSize to provide the size of the caller-allocated buffer..
/// </summary>
internal static string CallerAllocConstructorMustHaveBufferSizeConstantDescription {
get {
@@ -223,29 +223,29 @@ namespace Microsoft.Interop {
}
/// <summary>
- /// Looks up a localized string similar to Use &apos;GeneratedDllImportAttribute&apos; instead of &apos;DllImportAttribute&apos; to generate P/Invoke marshalling code at compile time.
+ /// Looks up a localized string similar to Convert to &apos;GeneratedDllImport&apos;.
/// </summary>
- internal static string ConvertToGeneratedDllImportDescription {
+ internal static string ConvertToGeneratedDllImport {
get {
- return ResourceManager.GetString("ConvertToGeneratedDllImportDescription", resourceCulture);
+ return ResourceManager.GetString("ConvertToGeneratedDllImport", resourceCulture);
}
}
/// <summary>
- /// Looks up a localized string similar to Mark the method &apos;{0}&apos; with &apos;GeneratedDllImportAttribute&apos; instead of &apos;DllImportAttribute&apos; to generate P/Invoke marshalling code at compile time.
+ /// Looks up a localized string similar to Use &apos;GeneratedDllImportAttribute&apos; instead of &apos;DllImportAttribute&apos; to generate P/Invoke marshalling code at compile time.
/// </summary>
- internal static string ConvertToGeneratedDllImportMessage {
+ internal static string ConvertToGeneratedDllImportDescription {
get {
- return ResourceManager.GetString("ConvertToGeneratedDllImportMessage", resourceCulture);
+ return ResourceManager.GetString("ConvertToGeneratedDllImportDescription", resourceCulture);
}
}
/// <summary>
- /// Looks up a localized string similar to Convert to &apos;GeneratedDllImport&apos;.
+ /// Looks up a localized string similar to Mark the method &apos;{0}&apos; with &apos;GeneratedDllImportAttribute&apos; instead of &apos;DllImportAttribute&apos; to generate P/Invoke marshalling code at compile time.
/// </summary>
- internal static string ConvertToGeneratedDllImportNoPreprocessor {
+ internal static string ConvertToGeneratedDllImportMessage {
get {
- return ResourceManager.GetString("ConvertToGeneratedDllImportNoPreprocessor", resourceCulture);
+ return ResourceManager.GetString("ConvertToGeneratedDllImportMessage", resourceCulture);
}
}
@@ -268,15 +268,6 @@ namespace Microsoft.Interop {
}
/// <summary>
- /// Looks up a localized string similar to Convert to &apos;GeneratedDllImport&apos; under a preprocessor define.
- /// </summary>
- internal static string ConvertToGeneratedDllImportWithPreprocessor {
- get {
- return ResourceManager.GetString("ConvertToGeneratedDllImportWithPreprocessor", resourceCulture);
- }
- }
-
- /// <summary>
/// Looks up a localized string similar to The specified parameter needs to be marshalled from managed to native, but the native type &apos;{0}&apos; does not support it..
/// </summary>
internal static string CustomTypeMarshallingManagedToNativeUnsupported {
diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.resx b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.resx
index a05f66fac1e..c3f3d9694fc 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.resx
+++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.resx
@@ -171,15 +171,15 @@
<data name="ConstantAndElementCountInfoDisallowed" xml:space="preserve">
<value>Only one of 'ConstantElementCount' or 'ElementCountInfo' may be used in a 'MarshalUsingAttribute' for a given 'ElementIndirectionLevel'</value>
</data>
+ <data name="ConvertToGeneratedDllImport" xml:space="preserve">
+ <value>Convert to 'GeneratedDllImport'</value>
+ </data>
<data name="ConvertToGeneratedDllImportDescription" xml:space="preserve">
<value>Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time</value>
</data>
<data name="ConvertToGeneratedDllImportMessage" xml:space="preserve">
<value>Mark the method '{0}' with 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time</value>
</data>
- <data name="ConvertToGeneratedDllImportNoPreprocessor" xml:space="preserve">
- <value>Convert to 'GeneratedDllImport'</value>
- </data>
<data name="ConvertToGeneratedDllImportTitle" xml:space="preserve">
<value>Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time</value>
</data>
@@ -187,9 +187,6 @@
<value>Conversion to 'GeneratedDllImport' may change behavior and compatibility. See {0} for more information.</value>
<comment>{0} is a documentation link</comment>
</data>
- <data name="ConvertToGeneratedDllImportWithPreprocessor" xml:space="preserve">
- <value>Convert to 'GeneratedDllImport' under a preprocessor define</value>
- </data>
<data name="CustomTypeMarshallingManagedToNativeUnsupported" xml:space="preserve">
<value>The specified parameter needs to be marshalled from managed to native, but the native type '{0}' does not support it.</value>
</data>
diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/ConvertToGeneratedDllImportFixerTests.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/ConvertToGeneratedDllImportFixerTests.cs
index 26d3914320e..a818ba851ee 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/ConvertToGeneratedDllImportFixerTests.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/ConvertToGeneratedDllImportFixerTests.cs
@@ -17,10 +17,8 @@ namespace DllImportGenerator.UnitTests
[ActiveIssue("https://github.com/dotnet/runtime/issues/60650", TestRuntimes.Mono)]
public class ConvertToGeneratedDllImportFixerTests
{
- [ConditionalTheory]
- [InlineData(true)]
- [InlineData(false)]
- public async Task Basic(bool usePreprocessorDefines)
+ [ConditionalFact]
+ public async Task Basic()
{
string source = @$"
using System.Runtime.InteropServices;
@@ -30,20 +28,7 @@ partial class Test
public static extern int [|Method|](out int ret);
}}";
// Fixed source will have CS8795 (Partial method must have an implementation) without generator run
- string fixedSource = usePreprocessorDefines
- ? @$"
-using System.Runtime.InteropServices;
-partial class Test
-{{
-#if DLLIMPORTGENERATOR_ENABLED
- [GeneratedDllImport(""DoesNotExist"")]
- public static partial int {{|CS8795:Method|}}(out int ret);
-#else
- [DllImport(""DoesNotExist"")]
- public static extern int Method(out int ret);
-#endif
-}}"
- : @$"
+ string fixedSource = @$"
using System.Runtime.InteropServices;
partial class Test
{{
@@ -52,14 +37,11 @@ partial class Test
}}";
await VerifyCS.VerifyCodeFixAsync(
source,
- fixedSource,
- usePreprocessorDefines ? WithPreprocessorDefinesKey : NoPreprocessorDefinesKey);
+ fixedSource);
}
- [ConditionalTheory]
- [InlineData(true)]
- [InlineData(false)]
- public async Task Comments(bool usePreprocessorDefines)
+ [ConditionalFact]
+ public async Task Comments()
{
string source = @$"
using System.Runtime.InteropServices;
@@ -75,32 +57,7 @@ partial class Test
public static extern int [|Method2|](out int ret);
}}";
// Fixed source will have CS8795 (Partial method must have an implementation) without generator run
- string fixedSource = usePreprocessorDefines
- ? @$"
-using System.Runtime.InteropServices;
-partial class Test
-{{
- // P/Invoke
-#if DLLIMPORTGENERATOR_ENABLED
- [GeneratedDllImport(/*name*/""DoesNotExist"")] // comment
- public static partial int {{|CS8795:Method1|}}(out int ret);
-#else
- [DllImport(/*name*/""DoesNotExist"")] // comment
- public static extern int Method1(out int ret);
-#endif
-
- /** P/Invoke **/
-#if DLLIMPORTGENERATOR_ENABLED
- [GeneratedDllImport(""DoesNotExist"") /*name*/]
- // < ... >
- public static partial int {{|CS8795:Method2|}}(out int ret);
-#else
- [DllImport(""DoesNotExist"") /*name*/]
- // < ... >
- public static extern int Method2(out int ret);
-#endif
-}}"
- : @$"
+ string fixedSource = @$"
using System.Runtime.InteropServices;
partial class Test
{{
@@ -115,14 +72,11 @@ partial class Test
}}";
await VerifyCS.VerifyCodeFixAsync(
source,
- fixedSource,
- usePreprocessorDefines ? WithPreprocessorDefinesKey : NoPreprocessorDefinesKey);
+ fixedSource);
}
- [ConditionalTheory]
- [InlineData(true)]
- [InlineData(false)]
- public async Task MultipleAttributes(bool usePreprocessorDefines)
+ [ConditionalFact]
+ public async Task MultipleAttributes()
{
string source = @$"
using System.Runtime.InteropServices;
@@ -137,32 +91,7 @@ partial class Test
public static extern int [|Method2|](out int ret);
}}";
// Fixed source will have CS8795 (Partial method must have an implementation) without generator run
- string fixedSource = usePreprocessorDefines
- ? @$"
-using System.Runtime.InteropServices;
-partial class Test
-{{
-#if DLLIMPORTGENERATOR_ENABLED
- [System.ComponentModel.Description(""Test""), GeneratedDllImport(""DoesNotExist"")]
- public static partial int {{|CS8795:Method1|}}(out int ret);
-#else
- [System.ComponentModel.Description(""Test""), DllImport(""DoesNotExist"")]
- public static extern int Method1(out int ret);
-#endif
-
-#if DLLIMPORTGENERATOR_ENABLED
- [System.ComponentModel.Description(""Test"")]
- [GeneratedDllImport(""DoesNotExist"")]
- [return: MarshalAs(UnmanagedType.I4)]
- public static partial int {{|CS8795:Method2|}}(out int ret);
-#else
- [System.ComponentModel.Description(""Test"")]
- [DllImport(""DoesNotExist"")]
- [return: MarshalAs(UnmanagedType.I4)]
- public static extern int Method2(out int ret);
-#endif
-}}"
- : @$"
+ string fixedSource = @$"
using System.Runtime.InteropServices;
partial class Test
{{
@@ -176,14 +105,11 @@ partial class Test
}}";
await VerifyCS.VerifyCodeFixAsync(
source,
- fixedSource,
- usePreprocessorDefines ? WithPreprocessorDefinesKey : NoPreprocessorDefinesKey);
+ fixedSource);
}
- [ConditionalTheory]
- [InlineData(true)]
- [InlineData(false)]
- public async Task NamedArguments(bool usePreprocessorDefines)
+ [ConditionalFact]
+ public async Task NamedArguments()
{
string source = @$"
using System.Runtime.InteropServices;
@@ -196,27 +122,7 @@ partial class Test
public static extern int [|Method2|](out int ret);
}}";
// Fixed source will have CS8795 (Partial method must have an implementation) without generator run
- string fixedSource = usePreprocessorDefines
- ? @$"
-using System.Runtime.InteropServices;
-partial class Test
-{{
-#if DLLIMPORTGENERATOR_ENABLED
- [GeneratedDllImport(""DoesNotExist"", EntryPoint = ""Entry"")]
- public static partial int {{|CS8795:Method1|}}(out int ret);
-#else
- [DllImport(""DoesNotExist"", EntryPoint = ""Entry"")]
- public static extern int Method1(out int ret);
-#endif
-
-#if DLLIMPORTGENERATOR_ENABLED
- [GeneratedDllImport(""DoesNotExist"", EntryPoint = ""Entry"", CharSet = CharSet.Unicode)]
- public static partial int {{|CS8795:Method2|}}(out int ret);
-#else
- [DllImport(""DoesNotExist"", EntryPoint = ""Entry"", CharSet = CharSet.Unicode)]
- public static extern int Method2(out int ret);
-#endif
-}}" : @$"
+ string fixedSource = @$"
using System.Runtime.InteropServices;
partial class Test
{{
@@ -228,14 +134,11 @@ partial class Test
}}";
await VerifyCS.VerifyCodeFixAsync(
source,
- fixedSource,
- usePreprocessorDefines ? WithPreprocessorDefinesKey : NoPreprocessorDefinesKey);
+ fixedSource);
}
- [ConditionalTheory]
- [InlineData(true)]
- [InlineData(false)]
- public async Task RemoveableNamedArguments(bool usePreprocessorDefines)
+ [ConditionalFact]
+ public async Task RemoveableNamedArguments()
{
string source = @$"
using System.Runtime.InteropServices;
@@ -248,27 +151,7 @@ partial class Test
public static extern int [|Method2|](out int ret);
}}";
// Fixed source will have CS8795 (Partial method must have an implementation) without generator run
- string fixedSource = usePreprocessorDefines
- ? @$"
-using System.Runtime.InteropServices;
-partial class Test
-{{
-#if DLLIMPORTGENERATOR_ENABLED
- [GeneratedDllImport(""DoesNotExist"", EntryPoint = ""Entry"")]
- public static partial int {{|CS8795:Method1|}}(out int ret);
-#else
- [DllImport(""DoesNotExist"", EntryPoint = ""Entry"", BestFitMapping = false)]
- public static extern int Method1(out int ret);
-#endif
-
-#if DLLIMPORTGENERATOR_ENABLED
- [GeneratedDllImport(""DoesNotExist"")]
- public static partial int {{|CS8795:Method2|}}(out int ret);
-#else
- [DllImport(""DoesNotExist"", ThrowOnUnmappableChar = false)]
- public static extern int Method2(out int ret);
-#endif
-}}" : @$"
+ string fixedSource = @$"
using System.Runtime.InteropServices;
partial class Test
{{
@@ -280,14 +163,11 @@ partial class Test
}}";
await VerifyCS.VerifyCodeFixAsync(
source,
- fixedSource,
- usePreprocessorDefines ? WithPreprocessorDefinesKey : NoPreprocessorDefinesKey);
+ fixedSource);
}
- [ConditionalTheory]
- [InlineData(true)]
- [InlineData(false)]
- public async Task ReplaceableExplicitPlatformDefaultCallingConvention(bool usePreprocessorDefines)
+ [ConditionalFact]
+ public async Task ReplaceableExplicitPlatformDefaultCallingConvention()
{
string source = @$"
using System.Runtime.InteropServices;
@@ -297,19 +177,7 @@ partial class Test
public static extern int [|Method1|](out int ret);
}}";
// Fixed source will have CS8795 (Partial method must have an implementation) without generator run
- string fixedSource = usePreprocessorDefines
- ? @$"
-using System.Runtime.InteropServices;
-partial class Test
-{{
-#if DLLIMPORTGENERATOR_ENABLED
- [GeneratedDllImport(""DoesNotExist"", EntryPoint = ""Entry"")]
- public static partial int {{|CS8795:Method1|}}(out int ret);
-#else
- [DllImport(""DoesNotExist"", EntryPoint = ""Entry"", CallingConvention = CallingConvention.Winapi)]
- public static extern int Method1(out int ret);
-#endif
-}}" : @$"
+ string fixedSource = @$"
using System.Runtime.InteropServices;
partial class Test
{{
@@ -318,20 +186,15 @@ partial class Test
}}";
await VerifyCS.VerifyCodeFixAsync(
source,
- fixedSource,
- usePreprocessorDefines ? WithPreprocessorDefinesKey : NoPreprocessorDefinesKey);
+ fixedSource);
}
[ConditionalTheory]
- [InlineData(CallingConvention.Cdecl, typeof(CallConvCdecl), true)]
- [InlineData(CallingConvention.Cdecl, typeof(CallConvCdecl), false)]
- [InlineData(CallingConvention.StdCall, typeof(CallConvStdcall), true)]
- [InlineData(CallingConvention.StdCall, typeof(CallConvStdcall), false)]
- [InlineData(CallingConvention.ThisCall, typeof(CallConvThiscall), true)]
- [InlineData(CallingConvention.ThisCall, typeof(CallConvThiscall), false)]
- [InlineData(CallingConvention.FastCall, typeof(CallConvFastcall), true)]
- [InlineData(CallingConvention.FastCall, typeof(CallConvFastcall), false)]
- public async Task ReplaceableCallingConvention(CallingConvention callConv, Type callConvType, bool usePreprocessorDefines)
+ [InlineData(CallingConvention.Cdecl, typeof(CallConvCdecl))]
+ [InlineData(CallingConvention.StdCall, typeof(CallConvStdcall))]
+ [InlineData(CallingConvention.ThisCall, typeof(CallConvThiscall))]
+ [InlineData(CallingConvention.FastCall, typeof(CallConvFastcall))]
+ public async Task ReplaceableCallingConvention(CallingConvention callConv, Type callConvType)
{
string source = @$"
using System.Runtime.InteropServices;
@@ -341,20 +204,7 @@ partial class Test
public static extern int [|Method1|](out int ret);
}}";
// Fixed source will have CS8795 (Partial method must have an implementation) without generator run
- string fixedSource = usePreprocessorDefines
- ? @$"
-using System.Runtime.InteropServices;
-partial class Test
-{{
-#if DLLIMPORTGENERATOR_ENABLED
- [GeneratedDllImport(""DoesNotExist"", EntryPoint = ""Entry"")]
- [UnmanagedCallConv(CallConvs = new System.Type[] {{ typeof({callConvType.FullName}) }})]
- public static partial int {{|CS8795:Method1|}}(out int ret);
-#else
- [DllImport(""DoesNotExist"", EntryPoint = ""Entry"", CallingConvention = CallingConvention.{callConv})]
- public static extern int Method1(out int ret);
-#endif
-}}" : @$"
+ string fixedSource = @$"
using System.Runtime.InteropServices;
partial class Test
{{
@@ -364,14 +214,11 @@ partial class Test
}}";
await VerifyCS.VerifyCodeFixAsync(
source,
- fixedSource,
- usePreprocessorDefines ? WithPreprocessorDefinesKey : NoPreprocessorDefinesKey);
+ fixedSource);
}
- [ConditionalTheory]
- [InlineData(true)]
- [InlineData(false)]
- public async Task PreferredAttributeOrder(bool usePreprocessorDefines)
+ [ConditionalFact]
+ public async Task PreferredAttributeOrder()
{
string source = @$"
using System.Runtime.InteropServices;
@@ -381,19 +228,7 @@ partial class Test
public static extern int [|Method|](out int ret);
}}";
// Fixed source will have CS8795 (Partial method must have an implementation) without generator run
- string fixedSource = usePreprocessorDefines
- ? @$"
-using System.Runtime.InteropServices;
-partial class Test
-{{
-#if DLLIMPORTGENERATOR_ENABLED
- [GeneratedDllImport(""DoesNotExist"", EntryPoint = ""Entry"", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
- public static partial int {{|CS8795:Method|}}(out int ret);
-#else
- [DllImport(""DoesNotExist"", EntryPoint = ""Entry"", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
- public static extern int Method(out int ret);
-#endif
-}}" : @$"
+ string fixedSource = @$"
using System.Runtime.InteropServices;
partial class Test
{{
@@ -402,8 +237,7 @@ partial class Test
}}";
await VerifyCS.VerifyCodeFixAsync(
source,
- fixedSource,
- usePreprocessorDefines ? WithPreprocessorDefinesKey : NoPreprocessorDefinesKey);
+ fixedSource);
}
}
}
diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Verifiers/CSharpCodeFixVerifier.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Verifiers/CSharpCodeFixVerifier.cs
index d4ed1c02c5c..ae7fd894010 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Verifiers/CSharpCodeFixVerifier.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Verifiers/CSharpCodeFixVerifier.cs
@@ -44,22 +44,20 @@ namespace DllImportGenerator.UnitTests.Verifiers
}
/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.VerifyCodeFixAsync(string, string)"/>
- public static async Task VerifyCodeFixAsync(string source, string fixedSource, string? codeActionEquivalenceKey = null)
- => await VerifyCodeFixAsync(source, DiagnosticResult.EmptyDiagnosticResults, fixedSource, codeActionEquivalenceKey);
+ public static async Task VerifyCodeFixAsync(string source, string fixedSource)
+ => await VerifyCodeFixAsync(source, DiagnosticResult.EmptyDiagnosticResults, fixedSource);
/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.VerifyCodeFixAsync(string, DiagnosticResult, string)"/>
- public static async Task VerifyCodeFixAsync(string source, DiagnosticResult expected, string fixedSource, string? codeActionEquivalenceKey = null)
- => await VerifyCodeFixAsync(source, new[] { expected }, fixedSource, codeActionEquivalenceKey);
+ public static async Task VerifyCodeFixAsync(string source, DiagnosticResult expected, string fixedSource)
+ => await VerifyCodeFixAsync(source, new[] { expected }, fixedSource);
/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.VerifyCodeFixAsync(string, DiagnosticResult[], string)"/>
- public static async Task VerifyCodeFixAsync(string source, DiagnosticResult[] expected, string fixedSource, string? codeActionEquivalenceKey = null)
+ public static async Task VerifyCodeFixAsync(string source, DiagnosticResult[] expected, string fixedSource)
{
var test = new Test
{
TestCode = source,
FixedCode = fixedSource,
- CodeActionEquivalenceKey = codeActionEquivalenceKey,
- CodeActionValidationMode = CodeActionValidationMode.None,
};
test.ExpectedDiagnostics.AddRange(expected);
@@ -117,9 +115,6 @@ namespace DllImportGenerator.UnitTests.Verifiers
});
}
- protected override ParseOptions CreateParseOptions()
- => ((CSharpParseOptions)base.CreateParseOptions()).WithPreprocessorSymbols("DLLIMPORTGENERATOR_ENABLED");
-
protected override async Task RunImplAsync(CancellationToken cancellationToken)
{
try