From 875e6cb76be6385a84ce977bee85757d8ab685c3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:43:01 -0700 Subject: [PATCH 01/98] Use primary constructors --- ...rpAddAccessibilityModifiersCodeFixProvider.cs | 12 +++--------- .../CSharpAddAccessibilityModifiersService.cs | 11 +++-------- ...pAddAnonymousTypeMemberNameCodeFixProvider.cs | 10 +++------- .../AddBraces/CSharpAddBracesCodeFixProvider.cs | 11 +++-------- .../AddInheritdocCodeFixProvider.cs | 10 +++------- .../CSharpAddObsoleteAttributeCodeFixProvider.cs | 16 +++++----------- .../CSharpAddParameterCodeFixProvider.cs | 10 +++------- .../CSharpAliasAmbiguousTypeCodeFixProvider.cs | 10 +++------- ...ignOutParametersAboveReturnCodeFixProvider.cs | 10 +++------- .../AssignOutParametersAtStartCodeFixProvider.cs | 10 +++------- ...ressionInInterpolatedStringCodeFixProvider.cs | 10 +++------- ...CSharpResolveConflictMarkerCodeFixProvider.cs | 12 ++++-------- .../ConvertNamespaceCodeFixProvider.cs | 9 +++------ ...SwitchStatementToExpressionCodeFixProvider.cs | 10 +++------- .../CSharpConvertToAsyncMethodCodeFixProvider.cs | 10 +++------- 15 files changed, 48 insertions(+), 113 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersCodeFixProvider.cs index 539d47eb743e1..57ae84194335c 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersCodeFixProvider.cs @@ -2,25 +2,19 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Composition; using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.AddAccessibilityModifiers; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Host.Mef; namespace Microsoft.CodeAnalysis.CSharp.AddAccessibilityModifiers; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddAccessibilityModifiers), Shared] -internal class CSharpAddAccessibilityModifiersCodeFixProvider : AbstractAddAccessibilityModifiersCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAddAccessibilityModifiersCodeFixProvider() : AbstractAddAccessibilityModifiersCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAddAccessibilityModifiersCodeFixProvider() - { - } - protected override SyntaxNode MapToDeclarator(SyntaxNode node) { switch (node) diff --git a/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersService.cs b/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersService.cs index 265d06d8b08c1..62b52a9e97e5f 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersService.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersService.cs @@ -10,11 +10,6 @@ namespace Microsoft.CodeAnalysis.CSharp.AddAccessibilityModifiers; [ExportLanguageService(typeof(IAddAccessibilityModifiersService), LanguageNames.CSharp), Shared] -internal class CSharpAddAccessibilityModifiersService : CSharpAddAccessibilityModifiers, IAddAccessibilityModifiersService -{ - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpAddAccessibilityModifiersService() - { - } -} +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpAddAccessibilityModifiersService() : CSharpAddAccessibilityModifiers, IAddAccessibilityModifiersService; diff --git a/src/Analyzers/CSharp/CodeFixes/AddAnonymousTypeMemberName/CSharpAddAnonymousTypeMemberNameCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AddAnonymousTypeMemberName/CSharpAddAnonymousTypeMemberNameCodeFixProvider.cs index d5bf25d66e50a..35252af110f14 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddAnonymousTypeMemberName/CSharpAddAnonymousTypeMemberNameCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddAnonymousTypeMemberName/CSharpAddAnonymousTypeMemberNameCodeFixProvider.cs @@ -14,7 +14,9 @@ namespace Microsoft.CodeAnalysis.CSharp.AddAnonymousTypeMemberName; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddAnonymousTypeMemberName), Shared] -internal class CSharpAddAnonymousTypeMemberNameCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAddAnonymousTypeMemberNameCodeFixProvider() : AbstractAddAnonymousTypeMemberNameCodeFixProvider< ExpressionSyntax, AnonymousObjectCreationExpressionSyntax, @@ -22,12 +24,6 @@ internal class CSharpAddAnonymousTypeMemberNameCodeFixProvider { private const string CS0746 = nameof(CS0746); // Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access. - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAddAnonymousTypeMemberNameCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS0746]; diff --git a/src/Analyzers/CSharp/CodeFixes/AddBraces/CSharpAddBracesCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AddBraces/CSharpAddBracesCodeFixProvider.cs index ce87505e16a52..64b8379d9d73f 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddBraces/CSharpAddBracesCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddBraces/CSharpAddBracesCodeFixProvider.cs @@ -7,7 +7,6 @@ using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.Diagnostics; @@ -16,14 +15,10 @@ namespace Microsoft.CodeAnalysis.CSharp.Diagnostics.AddBraces; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddBraces), Shared] -internal sealed class CSharpAddBracesCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAddBracesCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAddBracesCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.AddBracesDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/AddInheritdoc/AddInheritdocCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AddInheritdoc/AddInheritdocCodeFixProvider.cs index b8bc2a6442d2a..c835f9f901206 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddInheritdoc/AddInheritdocCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddInheritdoc/AddInheritdocCodeFixProvider.cs @@ -21,19 +21,15 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.AddInheritdoc; using static CSharpSyntaxTokens; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddInheritdoc), Shared] -internal sealed class AddInheritdocCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class AddInheritdocCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { /// /// CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' /// private const string CS1591 = nameof(CS1591); - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public AddInheritdocCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [CS1591]; public override async Task RegisterCodeFixesAsync(CodeFixContext context) diff --git a/src/Analyzers/CSharp/CodeFixes/AddObsoleteAttribute/CSharpAddObsoleteAttributeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AddObsoleteAttribute/CSharpAddObsoleteAttributeCodeFixProvider.cs index da69e0b653a9e..1c98d5c0e4a6f 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddObsoleteAttribute/CSharpAddObsoleteAttributeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddObsoleteAttribute/CSharpAddObsoleteAttributeCodeFixProvider.cs @@ -13,8 +13,10 @@ namespace Microsoft.CodeAnalysis.CSharp.AddObsoleteAttribute; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddObsoleteAttribute), Shared] -internal class CSharpAddObsoleteAttributeCodeFixProvider - : AbstractAddObsoleteAttributeCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpAddObsoleteAttributeCodeFixProvider() + : AbstractAddObsoleteAttributeCodeFixProvider(CSharpSyntaxFacts.Instance, CSharpCodeFixesResources.Add_Obsolete) { public override ImmutableArray FixableDiagnosticIds { get; } = [ @@ -22,14 +24,6 @@ internal class CSharpAddObsoleteAttributeCodeFixProvider "CS0618", "CS0672", "CS1062", - "CS1064" -, // The best overloaded Add method 'MyCollection.Add(int)' for the collection initializer element is obsolete" + "CS1064", ]; - - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpAddObsoleteAttributeCodeFixProvider() - : base(CSharpSyntaxFacts.Instance, CSharpCodeFixesResources.Add_Obsolete) - { - } } diff --git a/src/Analyzers/CSharp/CodeFixes/AddParameter/CSharpAddParameterCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AddParameter/CSharpAddParameterCodeFixProvider.cs index 339b59bf7270f..715604c917b58 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddParameter/CSharpAddParameterCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddParameter/CSharpAddParameterCodeFixProvider.cs @@ -18,7 +18,9 @@ namespace Microsoft.CodeAnalysis.CSharp.AddParameter; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddParameter), Shared] [ExtensionOrder(Before = PredefinedCodeFixProviderNames.GenerateConstructor)] -internal class CSharpAddParameterCodeFixProvider : AbstractAddParameterCodeFixProvider< +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAddParameterCodeFixProvider() : AbstractAddParameterCodeFixProvider< ArgumentSyntax, AttributeArgumentSyntax, ArgumentListSyntax, @@ -34,12 +36,6 @@ internal class CSharpAddParameterCodeFixProvider : AbstractAddParameterCodeFixPr private static readonly ImmutableArray AddParameterFixableDiagnosticIds = [CS1501, CS1503, CS1660, CS1729, CS1739]; - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAddParameterCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => AddParameterFixableDiagnosticIds; diff --git a/src/Analyzers/CSharp/CodeFixes/AliasAmbiguousType/CSharpAliasAmbiguousTypeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AliasAmbiguousType/CSharpAliasAmbiguousTypeCodeFixProvider.cs index 80d6a95e75451..03f739a6ed179 100644 --- a/src/Analyzers/CSharp/CodeFixes/AliasAmbiguousType/CSharpAliasAmbiguousTypeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AliasAmbiguousType/CSharpAliasAmbiguousTypeCodeFixProvider.cs @@ -13,19 +13,15 @@ namespace Microsoft.CodeAnalysis.CSharp.AliasAmbiguousType; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AliasAmbiguousType), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.FullyQualify)] -internal class CSharpAliasAmbiguousTypeCodeFixProvider : AbstractAliasAmbiguousTypeCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAliasAmbiguousTypeCodeFixProvider() : AbstractAliasAmbiguousTypeCodeFixProvider { /// /// 'reference' is an ambiguous reference between 'identifier' and 'identifier' /// private const string CS0104 = nameof(CS0104); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAliasAmbiguousTypeCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [CS0104]; diff --git a/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAboveReturnCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAboveReturnCodeFixProvider.cs index 074030de7ec6c..0c6bc32df6a13 100644 --- a/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAboveReturnCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAboveReturnCodeFixProvider.cs @@ -19,14 +19,10 @@ namespace Microsoft.CodeAnalysis.CSharp.AssignOutParameters; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AssignOutParametersAboveReturn), Shared] -internal class AssignOutParametersAboveReturnCodeFixProvider : AbstractAssignOutParametersCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class AssignOutParametersAboveReturnCodeFixProvider() : AbstractAssignOutParametersCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public AssignOutParametersAboveReturnCodeFixProvider() - { - } - protected override void TryRegisterFix(CodeFixContext context, Document document, SyntaxNode container, SyntaxNode location) { RegisterCodeFix(context, CSharpCodeFixesResources.Assign_out_parameters, nameof(CSharpCodeFixesResources.Assign_out_parameters)); diff --git a/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAtStartCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAtStartCodeFixProvider.cs index 68e6c53f9fa52..17ec3bec4b51d 100644 --- a/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAtStartCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AssignOutParameters/AssignOutParametersAtStartCodeFixProvider.cs @@ -17,14 +17,10 @@ namespace Microsoft.CodeAnalysis.CSharp.AssignOutParameters; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AssignOutParametersAtStart), Shared] -internal class AssignOutParametersAtStartCodeFixProvider : AbstractAssignOutParametersCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class AssignOutParametersAtStartCodeFixProvider() : AbstractAssignOutParametersCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public AssignOutParametersAtStartCodeFixProvider() - { - } - protected override void TryRegisterFix(CodeFixContext context, Document document, SyntaxNode container, SyntaxNode location) { // Don't offer if we're already the starting statement of the container. This case will diff --git a/src/Analyzers/CSharp/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs index dae9100c4191b..be9a3102fe507 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs @@ -21,16 +21,12 @@ namespace Microsoft.CodeAnalysis.CSharp.ConditionalExpressionInStringInterpolati using static CSharpSyntaxTokens; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddParenthesesAroundConditionalExpressionInInterpolatedString), Shared] -internal class CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider() : CodeFixProvider { private const string CS8361 = nameof(CS8361); //A conditional expression cannot be used directly in a string interpolation because the ':' ends the interpolation.Parenthesize the conditional expression. - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider() - { - } - // CS8361 is a syntax error and it is unlikely that there is more than one CS8361 at a time. public override FixAllProvider? GetFixAllProvider() => null; diff --git a/src/Analyzers/CSharp/CodeFixes/ConflictMarkerResolution/CSharpResolveConflictMarkerCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConflictMarkerResolution/CSharpResolveConflictMarkerCodeFixProvider.cs index 6ec47426307a4..c476de4e37ebe 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConflictMarkerResolution/CSharpResolveConflictMarkerCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConflictMarkerResolution/CSharpResolveConflictMarkerCodeFixProvider.cs @@ -12,14 +12,10 @@ namespace Microsoft.CodeAnalysis.CSharp.ConflictMarkerResolution; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConflictMarkerResolution), Shared] -internal class CSharpResolveConflictMarkerCodeFixProvider : AbstractResolveConflictMarkerCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpResolveConflictMarkerCodeFixProvider() + : AbstractResolveConflictMarkerCodeFixProvider(CSharpSyntaxKinds.Instance, CS8300) { private const string CS8300 = nameof(CS8300); // Merge conflict marker encountered - - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpResolveConflictMarkerCodeFixProvider() - : base(CSharpSyntaxKinds.Instance, CS8300) - { - } } diff --git a/src/Analyzers/CSharp/CodeFixes/ConvertNamespace/ConvertNamespaceCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConvertNamespace/ConvertNamespaceCodeFixProvider.cs index 2007769def97e..b39e9e57791f8 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConvertNamespace/ConvertNamespaceCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConvertNamespace/ConvertNamespaceCodeFixProvider.cs @@ -21,13 +21,10 @@ namespace Microsoft.CodeAnalysis.CSharp.ConvertNamespace; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConvertNamespace), Shared] -internal class ConvertNamespaceCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class ConvertNamespaceCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public ConvertNamespaceCodeFixProvider() - { - } public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseBlockScopedNamespaceDiagnosticId, IDEDiagnosticIds.UseFileScopedNamespaceDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionCodeFixProvider.cs index 97263cf4f55c8..43785bf880ddb 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionCodeFixProvider.cs @@ -27,14 +27,10 @@ namespace Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression; using Constants = ConvertSwitchStatementToExpressionConstants; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConvertSwitchStatementToExpression), Shared] -internal sealed partial class ConvertSwitchStatementToExpressionCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed partial class ConvertSwitchStatementToExpressionCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public ConvertSwitchStatementToExpressionCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.ConvertSwitchStatementToExpressionDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/ConvertToAsync/CSharpConvertToAsyncMethodCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConvertToAsync/CSharpConvertToAsyncMethodCodeFixProvider.cs index c5cc94a864422..897a55d2ad9c3 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConvertToAsync/CSharpConvertToAsyncMethodCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConvertToAsync/CSharpConvertToAsyncMethodCodeFixProvider.cs @@ -16,19 +16,15 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.ConvertToAsync; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConvertToAsync), Shared] -internal class CSharpConvertToAsyncMethodCodeFixProvider : AbstractConvertToAsyncCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpConvertToAsyncMethodCodeFixProvider() : AbstractConvertToAsyncCodeFixProvider { /// /// Cannot await void. /// private const string CS4008 = nameof(CS4008); - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpConvertToAsyncMethodCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [CS4008]; protected override async Task GetDescriptionAsync( From 10e5a36a2db4c66ccf52af23c7125f6c789e9adb Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:43:48 -0700 Subject: [PATCH 02/98] Use primary constructors --- .../CSharpConvertToRecordCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/CSharpConvertToRecordCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/CSharpConvertToRecordCodeFixProvider.cs index 0db46321a101d..9bbbf1903eb6e 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/CSharpConvertToRecordCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConvertToRecord/CSharpConvertToRecordCodeFixProvider.cs @@ -6,7 +6,6 @@ using System.Collections.Immutable; using System.Composition; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Host.Mef; @@ -15,16 +14,12 @@ namespace Microsoft.CodeAnalysis.CSharp.ConvertToRecord; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConvertToRecord), Shared] -internal class CSharpConvertToRecordCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpConvertToRecordCodeFixProvider() : CodeFixProvider { private const string CS8865 = nameof(CS8865); // Only records may inherit from records. - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpConvertToRecordCodeFixProvider() - { - } - public override FixAllProvider? GetFixAllProvider() => null; From c1ad7a1f2840d368f653979719614f082b967eac Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:44:17 -0700 Subject: [PATCH 03/98] Use primary constructors --- .../CSharpConvertTypeOfToNameOfCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/ConvertTypeOfToNameOf/CSharpConvertTypeOfToNameOfCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConvertTypeOfToNameOf/CSharpConvertTypeOfToNameOfCodeFixProvider.cs index 715736b25f3a1..7eebb4cffc71d 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConvertTypeOfToNameOf/CSharpConvertTypeOfToNameOfCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConvertTypeOfToNameOf/CSharpConvertTypeOfToNameOfCodeFixProvider.cs @@ -15,15 +15,11 @@ namespace Microsoft.CodeAnalysis.CSharp.ConvertTypeOfToNameOf; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConvertTypeOfToNameOf), Shared] -internal class CSharpConvertTypeOfToNameOfCodeFixProvider : AbstractConvertTypeOfToNameOfCodeFixProvider< +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpConvertTypeOfToNameOfCodeFixProvider() : AbstractConvertTypeOfToNameOfCodeFixProvider< MemberAccessExpressionSyntax> { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpConvertTypeOfToNameOfCodeFixProvider() - { - } - protected override string GetCodeFixTitle() => CSharpCodeFixesResources.Convert_typeof_to_nameof; From 7313a67c3399e4c76147ee6010bcf19c1e38cf7d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:44:33 -0700 Subject: [PATCH 04/98] Use primary constructors --- .../CSharpDisambiguateSameVariableCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs index 2abf253e24c64..f5c0e279aee6c 100644 --- a/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs @@ -10,7 +10,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.LanguageService; @@ -26,17 +25,13 @@ namespace Microsoft.CodeAnalysis.CSharp.DisambiguateSameVariable; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.DisambiguateSameVariable), Shared] -internal class CSharpDisambiguateSameVariableCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpDisambiguateSameVariableCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const string CS1717 = nameof(CS1717); // Assignment made to same variable; did you mean to assign something else? private const string CS1718 = nameof(CS1718); // Comparison made to same variable; did you mean to compare something else? - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpDisambiguateSameVariableCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS1717, CS1718]; From 21f91ea7bedaf44f722e91a059489e31f57b868a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:44:49 -0700 Subject: [PATCH 05/98] Use primary constructors --- .../CSharpAddDocCommentNodesCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpAddDocCommentNodesCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpAddDocCommentNodesCodeFixProvider.cs index 9ddd508ced16f..718b8dd754b94 100644 --- a/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpAddDocCommentNodesCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpAddDocCommentNodesCodeFixProvider.cs @@ -17,7 +17,9 @@ namespace Microsoft.CodeAnalysis.CSharp.DocumentationComments; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddDocCommentNodes), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.ImplementInterface)] -internal class CSharpAddDocCommentNodesCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAddDocCommentNodesCodeFixProvider() : AbstractAddDocCommentNodesCodeFixProvider { /// @@ -25,12 +27,6 @@ internal class CSharpAddDocCommentNodesCodeFixProvider /// private const string CS1573 = nameof(CS1573); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAddDocCommentNodesCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS1573]; protected override string NodeName { get; } = "param"; From f1f411e2a9e9d2a795442c9c744f6481314201d3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:45:09 -0700 Subject: [PATCH 06/98] Use primary constructors --- .../CSharpRemoveDocCommentNodeCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpRemoveDocCommentNodeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpRemoveDocCommentNodeCodeFixProvider.cs index f17292e1b14a3..057f99d094f6e 100644 --- a/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpRemoveDocCommentNodeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/DocumentationComments/CSharpRemoveDocCommentNodeCodeFixProvider.cs @@ -6,7 +6,6 @@ using System.Composition; using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.DocumentationComments; @@ -14,7 +13,9 @@ namespace Microsoft.CodeAnalysis.CSharp.DocumentationComments; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveDocCommentNode), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.ImplementInterface)] -internal class CSharpRemoveDocCommentNodeCodeFixProvider : +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpRemoveDocCommentNodeCodeFixProvider() : AbstractRemoveDocCommentNodeCodeFixProvider { /// @@ -32,12 +33,6 @@ internal class CSharpRemoveDocCommentNodeCodeFixProvider : /// private const string CS1710 = nameof(CS1710); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpRemoveDocCommentNodeCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS1571, CS1572, CS1710]; protected override string DocCommentSignifierToken { get; } = "///"; From a2a7b87bf11f54f4ee0e352e217c5f1747e7ba6b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:45:28 -0700 Subject: [PATCH 07/98] Use primary constructors --- .../FileHeaders/CSharpFileHeaderCodeFixProvider.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/FileHeaders/CSharpFileHeaderCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/FileHeaders/CSharpFileHeaderCodeFixProvider.cs index d549187a6f015..f9f3deda2e29a 100644 --- a/src/Analyzers/CSharp/CodeFixes/FileHeaders/CSharpFileHeaderCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/FileHeaders/CSharpFileHeaderCodeFixProvider.cs @@ -13,15 +13,10 @@ namespace Microsoft.CodeAnalysis.CSharp.FileHeaders; /// /// Implements a code fix for file header diagnostics. /// -[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.FileHeader)] -[Shared] -internal class CSharpFileHeaderCodeFixProvider : AbstractFileHeaderCodeFixProvider +[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.FileHeader), Shared] +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpFileHeaderCodeFixProvider() : AbstractFileHeaderCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpFileHeaderCodeFixProvider() - { - } - protected override AbstractFileHeaderHelper FileHeaderHelper => CSharpFileHeaderHelper.Instance; } From b4aea1e8d5be12eaf2b5e9654d27f9026abc298e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:45:44 -0700 Subject: [PATCH 08/98] Use primary constructors --- .../CSharpFixIncorrectConstraintCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs index e6666760eb187..e3fc27020e1e8 100644 --- a/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editing; @@ -19,17 +18,13 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.FixIncorrectConstraint; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.FixIncorrectConstraint), Shared] -internal class CSharpFixIncorrectConstraintCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpFixIncorrectConstraintCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const string CS9010 = nameof(CS9010); // Keyword 'enum' cannot be used as a constraint.Did you mean 'struct, System.Enum'? Net6 C:\github\repo_find_refs\Net6\Class1.cs 1 Active private const string CS9011 = nameof(CS9011); // 'delegate' cannot be used as a constraint.Did you mean 'System.Delegate'? Net6 C:\github\repo_find_refs\Net6\Class1.cs 1 Active - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpFixIncorrectConstraintCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [CS9010, CS9011]; From 2d8de0947d4710e1f081deddc36489b6cdb1ce85 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:46:06 -0700 Subject: [PATCH 09/98] Use primary constructors --- .../CSharpFixReturnTypeCodeFixProvider.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/FixReturnType/CSharpFixReturnTypeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/FixReturnType/CSharpFixReturnTypeCodeFixProvider.cs index f0daf69247ea2..6353bff86f3f5 100644 --- a/src/Analyzers/CSharp/CodeFixes/FixReturnType/CSharpFixReturnTypeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/FixReturnType/CSharpFixReturnTypeCodeFixProvider.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -24,20 +23,16 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.FixReturnType; /// Helps fix void-returning methods or local functions to return a correct type. /// [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.FixReturnType), Shared] -internal class CSharpFixReturnTypeCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpFixReturnTypeCodeFixProvider() + : SyntaxEditorBasedCodeFixProvider(supportsFixAll: false) { // error CS0127: Since 'M()' returns void, a return keyword must not be followed by an object expression // error CS1997: Since 'M()' is an async method that returns 'Task', a return keyword must not be followed by an object expression // error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement public override ImmutableArray FixableDiagnosticIds => ["CS0127", "CS1997", "CS0201"]; - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpFixReturnTypeCodeFixProvider() - : base(supportsFixAll: false) - { - } - public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; From e4aa83717ba11db9351db9188b3a26fa88e12bb2 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:46:23 -0700 Subject: [PATCH 10/98] Use primary constructors --- .../ForEachCast/CSharpForEachCastCodeFixProvider.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/ForEachCast/CSharpForEachCastCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ForEachCast/CSharpForEachCastCodeFixProvider.cs index 1a10b3216eec0..c066622935221 100644 --- a/src/Analyzers/CSharp/CodeFixes/ForEachCast/CSharpForEachCastCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ForEachCast/CSharpForEachCastCodeFixProvider.cs @@ -3,9 +3,7 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Composition; -using System.Text; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.ForEachCast; @@ -15,14 +13,10 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.ForEachCast; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ForEachCast), Shared] -internal class CSharpForEachCastCodeFixProvider : AbstractForEachCastCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpForEachCastCodeFixProvider() : AbstractForEachCastCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpForEachCastCodeFixProvider() - { - } - protected override ITypeSymbol GetForEachElementType( SemanticModel semanticModel, CommonForEachStatementSyntax forEachStatement) { From 47e73dd012dc79881f1a1a672fd65eb7c2236b0d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:46:41 -0700 Subject: [PATCH 11/98] Use primary constructors --- .../Formatting/CSharpFormattingCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/Formatting/CSharpFormattingCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/Formatting/CSharpFormattingCodeFixProvider.cs index 78aede7a1ed01..911afb37bef69 100644 --- a/src/Analyzers/CSharp/CodeFixes/Formatting/CSharpFormattingCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/Formatting/CSharpFormattingCodeFixProvider.cs @@ -12,13 +12,9 @@ namespace Microsoft.CodeAnalysis.CodeStyle; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.FixFormatting), Shared] -internal class CSharpFormattingCodeFixProvider : AbstractFormattingCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpFormattingCodeFixProvider() : AbstractFormattingCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpFormattingCodeFixProvider() - { - } - protected override ISyntaxFormatting SyntaxFormatting => CSharpSyntaxFormatting.Instance; } From a64561f48356483277b3d26b3f3644fecba4dcfa Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:47:03 -0700 Subject: [PATCH 12/98] Use primary constructors --- .../CodeFixes/HideBase/HideBaseCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/HideBase/HideBaseCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/HideBase/HideBaseCodeFixProvider.cs index a1a9c282c4214..cfc813e2319e6 100644 --- a/src/Analyzers/CSharp/CodeFixes/HideBase/HideBaseCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/HideBase/HideBaseCodeFixProvider.cs @@ -7,7 +7,6 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Shared.Extensions; @@ -15,16 +14,12 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.HideBase; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddNew), Shared] -internal partial class HideBaseCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class HideBaseCodeFixProvider() : CodeFixProvider { internal const string CS0108 = nameof(CS0108); // 'SomeClass.SomeMember' hides inherited member 'SomeClass.SomeMember'. Use the new keyword if hiding was intended. - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public HideBaseCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [CS0108]; public override FixAllProvider GetFixAllProvider() From 7efd3964263144613177fe16da8702c50bfaad79 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:47:22 -0700 Subject: [PATCH 13/98] Use primary constructors --- .../CSharpInlineDeclarationCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/InlineDeclaration/CSharpInlineDeclarationCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/InlineDeclaration/CSharpInlineDeclarationCodeFixProvider.cs index 49732b79122a2..526ca834a7acd 100644 --- a/src/Analyzers/CSharp/CodeFixes/InlineDeclaration/CSharpInlineDeclarationCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/InlineDeclaration/CSharpInlineDeclarationCodeFixProvider.cs @@ -18,7 +18,6 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Formatting; -using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Utilities; using Microsoft.CodeAnalysis.Text; @@ -28,14 +27,10 @@ namespace Microsoft.CodeAnalysis.CSharp.InlineDeclaration; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.InlineDeclaration), Shared] -internal partial class CSharpInlineDeclarationCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class CSharpInlineDeclarationCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpInlineDeclarationCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.InlineDeclarationDiagnosticId]; From 20c38771298c55cae413023900ce1beace26e70d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:47:37 -0700 Subject: [PATCH 14/98] Use primary constructors --- ...okeDelegateWithConditionalAccessCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.cs index fe53a9bf2da42..00ce0cc496c32 100644 --- a/src/Analyzers/CSharp/CodeFixes/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.cs @@ -10,7 +10,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -25,14 +24,10 @@ namespace Microsoft.CodeAnalysis.CSharp.InvokeDelegateWithConditionalAccess; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.InvokeDelegateWithConditionalAccess), Shared] -internal partial class InvokeDelegateWithConditionalAccessCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class InvokeDelegateWithConditionalAccessCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public InvokeDelegateWithConditionalAccessCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.InvokeDelegateWithConditionalAccessId]; // Filter out the diagnostics we created for the faded out code. We don't want From 70ede96cf3a47198fee4304c72cfced4a86d3cd2 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:47:57 -0700 Subject: [PATCH 15/98] Use primary constructors --- .../Iterator/CSharpAddYieldCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpAddYieldCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpAddYieldCodeFixProvider.cs index dba1cfc6890d8..9a25f4ae39100 100644 --- a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpAddYieldCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpAddYieldCodeFixProvider.cs @@ -22,7 +22,9 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.Iterator; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ChangeToYield), Shared] -internal class CSharpAddYieldCodeFixProvider : AbstractIteratorCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpAddYieldCodeFixProvider() : AbstractIteratorCodeFixProvider { /// /// CS0029: Cannot implicitly convert from type 'x' to 'y' @@ -34,12 +36,6 @@ internal class CSharpAddYieldCodeFixProvider : AbstractIteratorCodeFixProvider /// private const string CS0266 = nameof(CS0266); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAddYieldCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get { return [CS0029, CS0266]; } From 32142a66c6bb6a48350ca86bc3ea2f4412cc4f40 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:48:17 -0700 Subject: [PATCH 16/98] Use primary constructors --- .../CSharpChangeToIEnumerableCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs index 3043fe7f66fa2..63b73726a130d 100644 --- a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs @@ -21,19 +21,15 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.Iterator; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ChangeReturnType), Shared] -internal class CSharpChangeToIEnumerableCodeFixProvider : AbstractIteratorCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal class CSharpChangeToIEnumerableCodeFixProvider() : AbstractIteratorCodeFixProvider { /// /// CS1624: The body of 'x' cannot be an iterator block because 'y' is not an iterator interface type /// private const string CS1624 = nameof(CS1624); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpChangeToIEnumerableCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get { return [CS1624]; } From 357adee3ee191c7ff16d1a788e5a300177c6671d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:48:38 -0700 Subject: [PATCH 17/98] Use primary constructors --- .../CSharpChangeToIEnumerableCodeFixProvider.cs | 5 +---- .../CSharpMakeFieldReadonlyCodeFixProvider.cs | 10 +++------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs index 63b73726a130d..63e5af1308a06 100644 --- a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs @@ -30,10 +30,7 @@ internal class CSharpChangeToIEnumerableCodeFixProvider() : AbstractIteratorCode /// private const string CS1624 = nameof(CS1624); - public override ImmutableArray FixableDiagnosticIds - { - get { return [CS1624]; } - } + public override ImmutableArray FixableDiagnosticIds => [CS1624]; protected override async Task GetCodeFixAsync(SyntaxNode root, SyntaxNode node, Document document, Diagnostic diagnostics, CancellationToken cancellationToken) { diff --git a/src/Analyzers/CSharp/CodeFixes/MakeFieldReadonly/CSharpMakeFieldReadonlyCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeFieldReadonly/CSharpMakeFieldReadonlyCodeFixProvider.cs index 233c98d80d709..2a99380b0e0b8 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeFieldReadonly/CSharpMakeFieldReadonlyCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeFieldReadonly/CSharpMakeFieldReadonlyCodeFixProvider.cs @@ -13,14 +13,10 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeFieldReadonly; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeFieldReadonly), Shared] -internal class CSharpMakeFieldReadonlyCodeFixProvider : AbstractMakeFieldReadonlyCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpMakeFieldReadonlyCodeFixProvider() : AbstractMakeFieldReadonlyCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpMakeFieldReadonlyCodeFixProvider() - { - } - protected override SyntaxNode? GetInitializerNode(VariableDeclaratorSyntax declaration) => declaration.Initializer?.Value; From d7cc202c1f8be959488ee26d04e7c61ae523441c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:48:58 -0700 Subject: [PATCH 18/98] Use primary constructors --- .../MakeLocalFunctionStaticCodeFixProvider.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeFixProvider.cs index 949282ecddc0f..980bfb21c6060 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeFixProvider.cs @@ -2,13 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editing; @@ -17,14 +15,10 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeLocalFunctionStatic; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeLocalFunctionStatic), Shared] -internal class MakeLocalFunctionStaticCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class MakeLocalFunctionStaticCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public MakeLocalFunctionStaticCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.MakeLocalFunctionStaticDiagnosticId]; From 27cbefca157b3114035866d8efd6cd06b4f754c4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:49:14 -0700 Subject: [PATCH 19/98] Use primary constructors --- ...assInCapturedVariablesAsArgumentsCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/PassInCapturedVariablesAsArgumentsCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/PassInCapturedVariablesAsArgumentsCodeFixProvider.cs index 7ba958a71a6da..46b3d5b773af4 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/PassInCapturedVariablesAsArgumentsCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeLocalFunctionStatic/PassInCapturedVariablesAsArgumentsCodeFixProvider.cs @@ -20,16 +20,12 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeLocalFunctionStatic; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.PassInCapturedVariables), Shared] -internal sealed class PassInCapturedVariablesAsArgumentsCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class PassInCapturedVariablesAsArgumentsCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const string CS8421 = nameof(CS8421); // A static local function can't contain a reference to . - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public PassInCapturedVariablesAsArgumentsCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS8421]; public override Task RegisterCodeFixesAsync(CodeFixContext context) From 91aff87b847af560af33e79bbdcdd009bb595dea Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:49:29 -0700 Subject: [PATCH 20/98] Use primary constructors --- .../CSharpMakeMemberRequiredCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/MakeMemberRequired/CSharpMakeMemberRequiredCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeMemberRequired/CSharpMakeMemberRequiredCodeFixProvider.cs index 9497c77015b2e..3cbf78f745f56 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeMemberRequired/CSharpMakeMemberRequiredCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeMemberRequired/CSharpMakeMemberRequiredCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Composition; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -22,16 +21,12 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.MakeMemberRequired; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeMemberRequired), Shared] [ExtensionOrder(Before = PredefinedCodeFixProviderNames.DeclareAsNullable)] -internal sealed class CSharpMakeMemberRequiredCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpMakeMemberRequiredCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const string CS8618 = nameof(CS8618); // Non-nullable variable must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring it as nullable. - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpMakeMemberRequiredCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS8618]; From e9e5a8e9327155d8b5bc80c897d78b554c1a0984 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:49:50 -0700 Subject: [PATCH 21/98] Use primary constructors --- .../CSharpMakeMemberStaticCodeFixProvider.cs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/MakeMemberStatic/CSharpMakeMemberStaticCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeMemberStatic/CSharpMakeMemberStaticCodeFixProvider.cs index 8c747b4a83ddd..ee9773795d40a 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeMemberStatic/CSharpMakeMemberStaticCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeMemberStatic/CSharpMakeMemberStaticCodeFixProvider.cs @@ -6,7 +6,6 @@ using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; -using System.Linq; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Host.Mef; @@ -15,16 +14,11 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeMemberStatic; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeMemberStatic), Shared] -internal sealed class CSharpMakeMemberStaticCodeFixProvider : AbstractMakeMemberStaticCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpMakeMemberStaticCodeFixProvider() : AbstractMakeMemberStaticCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpMakeMemberStaticCodeFixProvider() - { - } - - public override ImmutableArray FixableDiagnosticIds { get; } = - ["CS0708"]; + public override ImmutableArray FixableDiagnosticIds { get; } = ["CS0708"]; protected override bool TryGetMemberDeclaration(SyntaxNode node, [NotNullWhen(true)] out SyntaxNode? memberDeclaration) { From 300542125fdd897e552b655c8dc31eeafbb77826 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:50:04 -0700 Subject: [PATCH 22/98] Use primary constructors --- .../CSharpMakeMethodAsynchronousCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/MakeMethodAsynchronous/CSharpMakeMethodAsynchronousCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeMethodAsynchronous/CSharpMakeMethodAsynchronousCodeFixProvider.cs index c24bdc78fec87..186ac162813d4 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeMethodAsynchronous/CSharpMakeMethodAsynchronousCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeMethodAsynchronous/CSharpMakeMethodAsynchronousCodeFixProvider.cs @@ -21,7 +21,9 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeMethodAsynchronous; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddAsync), Shared] -internal class CSharpMakeMethodAsynchronousCodeFixProvider : AbstractMakeMethodAsynchronousCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpMakeMethodAsynchronousCodeFixProvider() : AbstractMakeMethodAsynchronousCodeFixProvider { private const string CS4032 = nameof(CS4032); // The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. private const string CS4033 = nameof(CS4033); // The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. @@ -30,12 +32,6 @@ internal class CSharpMakeMethodAsynchronousCodeFixProvider : AbstractMakeMethodA private static readonly SyntaxToken s_asyncKeywordWithSpace = AsyncKeyword.WithoutTrivia().WithTrailingTrivia(Space); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpMakeMethodAsynchronousCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS4032, CS4033, CS4034, CS0246]; From aef5c26cf2834861a9eb1fb4b3828bece52334db Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:50:17 -0700 Subject: [PATCH 23/98] Use primary constructors --- .../CSharpMakeMethodSynchronousCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/MakeMethodSynchronous/CSharpMakeMethodSynchronousCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeMethodSynchronous/CSharpMakeMethodSynchronousCodeFixProvider.cs index 35a8ac00ac066..de80287f51aa6 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeMethodSynchronous/CSharpMakeMethodSynchronousCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeMethodSynchronous/CSharpMakeMethodSynchronousCodeFixProvider.cs @@ -18,16 +18,12 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeMethodSynchronous; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeMethodSynchronous), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.AddImport)] -internal class CSharpMakeMethodSynchronousCodeFixProvider : AbstractMakeMethodSynchronousCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpMakeMethodSynchronousCodeFixProvider() : AbstractMakeMethodSynchronousCodeFixProvider { private const string CS1998 = nameof(CS1998); // This async method lacks 'await' operators and will run synchronously. - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpMakeMethodSynchronousCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS1998]; protected override bool IsAsyncSupportingFunctionSyntax(SyntaxNode node) From a01ce6e24d1d9656f1915a8d06f49a0b2175205c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:50:31 -0700 Subject: [PATCH 24/98] Use primary constructors --- .../MakeRefStruct/MakeRefStructCodeFixProvider.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/MakeRefStruct/MakeRefStructCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeRefStruct/MakeRefStructCodeFixProvider.cs index 61ca1362d13fe..6ae9aebe5a155 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeRefStruct/MakeRefStructCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeRefStruct/MakeRefStructCodeFixProvider.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -13,22 +12,17 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Shared.Extensions; -using Microsoft.CodeAnalysis.Text; namespace Microsoft.CodeAnalysis.CSharp.MakeRefStruct; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeRefStruct), Shared] -internal class MakeRefStructCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class MakeRefStructCodeFixProvider() : CodeFixProvider { // Error CS8345: Field or auto-implemented property cannot be of certain type unless it is an instance member of a ref struct. private const string CS8345 = nameof(CS8345); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public MakeRefStructCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [CS8345]; From 4cc8f872e15e4e9e7843c2a89c7e964b1819d53f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:50:45 -0700 Subject: [PATCH 25/98] Use primary constructors --- ...CSharpMakeStatementAsynchronousCodeFixProvider.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/MakeStatementAsynchronous/CSharpMakeStatementAsynchronousCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeStatementAsynchronous/CSharpMakeStatementAsynchronousCodeFixProvider.cs index 848b7bc5a181e..1eddec0d520e9 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeStatementAsynchronous/CSharpMakeStatementAsynchronousCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeStatementAsynchronous/CSharpMakeStatementAsynchronousCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -20,17 +19,12 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.MakeStatementAsynchronous; using static CSharpSyntaxTokens; -using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeStatementAsynchronous), Shared] -internal class CSharpMakeStatementAsynchronousCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpMakeStatementAsynchronousCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpMakeStatementAsynchronousCodeFixProvider() - { - } - // error CS8414: foreach statement cannot operate on variables of type 'IAsyncEnumerable' because 'IAsyncEnumerable' does not contain a public instance definition for 'GetEnumerator'. Did you mean 'await foreach'? // error CS8418: 'IAsyncDisposable': type used in a using statement must be implicitly convertible to 'System.IDisposable'. Did you mean 'await using' rather than 'using'? public sealed override ImmutableArray FixableDiagnosticIds => ["CS8414", "CS8418"]; From 93e299ce7057c4a01004ef8ec64609d93d376e74 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:51:21 -0700 Subject: [PATCH 26/98] Use primary constructors --- .../CSharpMakeStructFieldsWritableCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/MakeStructFieldsWritable/CSharpMakeStructFieldsWritableCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeStructFieldsWritable/CSharpMakeStructFieldsWritableCodeFixProvider.cs index db0495d70e4d6..b9b1909edbdc0 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeStructFieldsWritable/CSharpMakeStructFieldsWritableCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeStructFieldsWritable/CSharpMakeStructFieldsWritableCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; @@ -19,14 +18,10 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeStructFieldsWritable; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeStructFieldsWritable), Shared] -internal class CSharpMakeStructFieldsWritableCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpMakeStructFieldsWritableCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpMakeStructFieldsWritableCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.MakeStructFieldsWritable]; From 0ae63bef8a340399f964e6729f72bb6e83042429 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:51:33 -0700 Subject: [PATCH 27/98] Use primary constructors --- .../CSharpMakeStructReadOnlyCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/MakeStructReadOnly/CSharpMakeStructReadOnlyCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeStructReadOnly/CSharpMakeStructReadOnlyCodeFixProvider.cs index 3f21860c25103..caf2cd69ff6c3 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeStructReadOnly/CSharpMakeStructReadOnlyCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeStructReadOnly/CSharpMakeStructReadOnlyCodeFixProvider.cs @@ -18,14 +18,10 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeStructReadOnly; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeStructReadOnly), Shared] -internal sealed class CSharpMakeStructReadOnlyCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpMakeStructReadOnlyCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpMakeStructReadOnlyCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.MakeStructReadOnlyDiagnosticId]; From d6a4cfa18162c9d25bcda617227a5437b3e43e1f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:52:16 -0700 Subject: [PATCH 28/98] Use primary constructors --- .../CSharpMakeStructReadOnlyCodeFixProvider.cs | 1 - .../CSharpMakeTypeAbstractCodeFixProvider.cs | 11 +++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/MakeStructReadOnly/CSharpMakeStructReadOnlyCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeStructReadOnly/CSharpMakeStructReadOnlyCodeFixProvider.cs index caf2cd69ff6c3..697d799433afc 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeStructReadOnly/CSharpMakeStructReadOnlyCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeStructReadOnly/CSharpMakeStructReadOnlyCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editing; diff --git a/src/Analyzers/CSharp/CodeFixes/MakeTypeAbstract/CSharpMakeTypeAbstractCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeTypeAbstract/CSharpMakeTypeAbstractCodeFixProvider.cs index 3cf6b45ddf1e2..0ec6147a8c1e5 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeTypeAbstract/CSharpMakeTypeAbstractCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeTypeAbstract/CSharpMakeTypeAbstractCodeFixProvider.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -13,14 +12,10 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeTypeAbstract; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeTypeAbstract), Shared] -internal sealed class CSharpMakeTypeAbstractCodeFixProvider : AbstractMakeTypeAbstractCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpMakeTypeAbstractCodeFixProvider() : AbstractMakeTypeAbstractCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpMakeTypeAbstractCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = ["CS0513"]; From 1b4bc002ae0829461897a20e4bfe41a5367a4638 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:52:31 -0700 Subject: [PATCH 29/98] Use primary constructors --- .../CSharpMakeTypePartialCodeFixProvider.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/MakeTypePartial/CSharpMakeTypePartialCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeTypePartial/CSharpMakeTypePartialCodeFixProvider.cs index be903b4c152b7..a8ca5d41a8a4a 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeTypePartial/CSharpMakeTypePartialCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeTypePartial/CSharpMakeTypePartialCodeFixProvider.cs @@ -12,16 +12,11 @@ namespace Microsoft.CodeAnalysis.CSharp.MakeTypePartial; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MakeTypePartial), Shared] -internal sealed class CSharpMakeTypePartialCodeFixProvider : AbstractMakeTypePartialCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpMakeTypePartialCodeFixProvider() : AbstractMakeTypePartialCodeFixProvider { private const string CS0260 = nameof(CS0260); // Missing partial modifier on declaration of type 'C'; another partial declaration of this type exists - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpMakeTypePartialCodeFixProvider() - { - } - - public override ImmutableArray FixableDiagnosticIds { get; } = - [CS0260]; + public override ImmutableArray FixableDiagnosticIds { get; } = [CS0260]; } From a186e300eb34568c53b2a7cc627195643795fa0a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:52:48 -0700 Subject: [PATCH 30/98] Use primary constructors --- ...harpChangeNamespaceToMatchFolderCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/MatchFolderAndNamespace/CSharpChangeNamespaceToMatchFolderCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MatchFolderAndNamespace/CSharpChangeNamespaceToMatchFolderCodeFixProvider.cs index e5d5a6a13936a..81777d0d08087 100644 --- a/src/Analyzers/CSharp/CodeFixes/MatchFolderAndNamespace/CSharpChangeNamespaceToMatchFolderCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MatchFolderAndNamespace/CSharpChangeNamespaceToMatchFolderCodeFixProvider.cs @@ -12,11 +12,6 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.MatchFolderAndNamespace; [Export(typeof(CSharpChangeNamespaceToMatchFolderCodeFixProvider))] [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ChangeNamespaceToMatchFolder), Shared] -internal class CSharpChangeNamespaceToMatchFolderCodeFixProvider : AbstractChangeNamespaceToMatchFolderCodeFixProvider -{ - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpChangeNamespaceToMatchFolderCodeFixProvider() - { - } -} +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpChangeNamespaceToMatchFolderCodeFixProvider() : AbstractChangeNamespaceToMatchFolderCodeFixProvider; From 814a56d9b10d5523d75660aa3f63253f6be18e7e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:53:07 -0700 Subject: [PATCH 31/98] Use primary constructors --- .../MisplacedUsingDirectivesCodeFixProvider.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/MisplacedUsingDirectives/MisplacedUsingDirectivesCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MisplacedUsingDirectives/MisplacedUsingDirectivesCodeFixProvider.cs index c0463c723161f..6657044d72b52 100644 --- a/src/Analyzers/CSharp/CodeFixes/MisplacedUsingDirectives/MisplacedUsingDirectivesCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MisplacedUsingDirectives/MisplacedUsingDirectivesCodeFixProvider.cs @@ -28,9 +28,10 @@ namespace Microsoft.CodeAnalysis.CSharp.MisplacedUsingDirectives; /// /// Implements a code fix for all misplaced using statements. /// -[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MoveMisplacedUsingDirectives)] -[Shared] -internal sealed partial class MisplacedUsingDirectivesCodeFixProvider : CodeFixProvider +[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.MoveMisplacedUsingDirectives), Shared] +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class MisplacedUsingDirectivesCodeFixProvider() : CodeFixProvider { private static readonly SyntaxAnnotation s_usingPlacementCodeFixAnnotation = new(nameof(s_usingPlacementCodeFixAnnotation)); @@ -40,12 +41,6 @@ internal sealed partial class MisplacedUsingDirectivesCodeFixProvider : CodeFixP private static readonly SyntaxAnnotation s_warningAnnotation = WarningAnnotation.Create( CSharpAnalyzersResources.Warning_colon_Moving_using_directives_may_change_code_meaning); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public MisplacedUsingDirectivesCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.MoveMisplacedUsingDirectivesDiagnosticId]; public override FixAllProvider GetFixAllProvider() From 05cfea1fd14747be5384b5a453a8928ad4db8b64 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:53:23 -0700 Subject: [PATCH 32/98] Use primary constructors --- .../ArrowExpressionClausePlacementCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/NewLines/ArrowExpressionClausePlacement/ArrowExpressionClausePlacementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/NewLines/ArrowExpressionClausePlacement/ArrowExpressionClausePlacementCodeFixProvider.cs index 0efae742c6ca0..91f10bc2d37bd 100644 --- a/src/Analyzers/CSharp/CodeFixes/NewLines/ArrowExpressionClausePlacement/ArrowExpressionClausePlacementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/NewLines/ArrowExpressionClausePlacement/ArrowExpressionClausePlacementCodeFixProvider.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; using System.Linq; @@ -22,14 +21,10 @@ namespace Microsoft.CodeAnalysis.CSharp.NewLines.ArrowExpressionClausePlacement; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ArrowExpressionClausePlacement), Shared] -internal sealed class ArrowExpressionClausePlacementCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class ArrowExpressionClausePlacementCodeFixProvider() : CodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public ArrowExpressionClausePlacementCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.ArrowExpressionClausePlacementDiagnosticId]; From b51cfd0b46172ef07e9af37faccbf9e6ca1deafe Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:53:35 -0700 Subject: [PATCH 33/98] Use primary constructors --- .../ConditionalExpressionPlacementCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/NewLines/ConditionalExpressionPlacement/ConditionalExpressionPlacementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/NewLines/ConditionalExpressionPlacement/ConditionalExpressionPlacementCodeFixProvider.cs index 8889157d918c2..50cce8f2d95b2 100644 --- a/src/Analyzers/CSharp/CodeFixes/NewLines/ConditionalExpressionPlacement/ConditionalExpressionPlacementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/NewLines/ConditionalExpressionPlacement/ConditionalExpressionPlacementCodeFixProvider.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; using System.Linq; @@ -22,14 +21,10 @@ namespace Microsoft.CodeAnalysis.CSharp.NewLines.ConditionalExpressionPlacement; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConditionalExpressionPlacement), Shared] -internal sealed class ConditionalExpressionPlacementCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class ConditionalExpressionPlacementCodeFixProvider() : CodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public ConditionalExpressionPlacementCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.ConditionalExpressionPlacementDiagnosticId]; From 5ef50792669dd0bde26db178918ecb122787b1ad Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:53:48 -0700 Subject: [PATCH 34/98] Use primary constructors --- .../ConsecutiveBracePlacementCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/NewLines/ConsecutiveBracePlacement/ConsecutiveBracePlacementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/NewLines/ConsecutiveBracePlacement/ConsecutiveBracePlacementCodeFixProvider.cs index 8fbb8bcdb29fc..6f37b38c9fce5 100644 --- a/src/Analyzers/CSharp/CodeFixes/NewLines/ConsecutiveBracePlacement/ConsecutiveBracePlacementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/NewLines/ConsecutiveBracePlacement/ConsecutiveBracePlacementCodeFixProvider.cs @@ -21,14 +21,10 @@ namespace Microsoft.CodeAnalysis.CSharp.NewLines.ConsecutiveBracePlacement; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConsecutiveBracePlacement), Shared] -internal sealed class ConsecutiveBracePlacementCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class ConsecutiveBracePlacementCodeFixProvider() : CodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public ConsecutiveBracePlacementCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.ConsecutiveBracePlacementDiagnosticId]; From a462902ab7bc55f5aee64aaaa0799ebc188d556d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:54:12 -0700 Subject: [PATCH 35/98] Use primary constructors --- .../ConstructorInitializerPlacementCodeFixProvider.cs | 10 +++------- .../EmbeddedStatementPlacementCodeFixProvider.cs | 10 +++------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/NewLines/ConstructorInitializerPlacement/ConstructorInitializerPlacementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/NewLines/ConstructorInitializerPlacement/ConstructorInitializerPlacementCodeFixProvider.cs index 7e012daf50346..fdb85c447f743 100644 --- a/src/Analyzers/CSharp/CodeFixes/NewLines/ConstructorInitializerPlacement/ConstructorInitializerPlacementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/NewLines/ConstructorInitializerPlacement/ConstructorInitializerPlacementCodeFixProvider.cs @@ -20,14 +20,10 @@ namespace Microsoft.CodeAnalysis.CSharp.NewLines.ConstructorInitializerPlacement; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConstructorInitializerPlacement), Shared] -internal sealed class ConstructorInitializerPlacementCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class ConstructorInitializerPlacementCodeFixProvider() : CodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public ConstructorInitializerPlacementCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.ConstructorInitializerPlacementDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/NewLines/EmbeddedStatementPlacement/EmbeddedStatementPlacementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/NewLines/EmbeddedStatementPlacement/EmbeddedStatementPlacementCodeFixProvider.cs index 45709ce592734..bf6a8be42bb2e 100644 --- a/src/Analyzers/CSharp/CodeFixes/NewLines/EmbeddedStatementPlacement/EmbeddedStatementPlacementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/NewLines/EmbeddedStatementPlacement/EmbeddedStatementPlacementCodeFixProvider.cs @@ -22,14 +22,10 @@ namespace Microsoft.CodeAnalysis.CSharp.NewLines.EmbeddedStatementPlacement; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.EmbeddedStatementPlacement), Shared] -internal sealed class EmbeddedStatementPlacementCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class EmbeddedStatementPlacementCodeFixProvider() : CodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public EmbeddedStatementPlacementCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.EmbeddedStatementPlacementDiagnosticId]; From 10a57ac0b96f1bc8c115ba030282ea3ff8709d94 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:54:32 -0700 Subject: [PATCH 36/98] Use primary constructors --- .../CSharpOrderModifiersCodeFixProvider.cs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/OrderModifiers/CSharpOrderModifiersCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/OrderModifiers/CSharpOrderModifiersCodeFixProvider.cs index 85de50c8f00fc..850b1c3761a3e 100644 --- a/src/Analyzers/CSharp/CodeFixes/OrderModifiers/CSharpOrderModifiersCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/OrderModifiers/CSharpOrderModifiersCodeFixProvider.cs @@ -5,11 +5,8 @@ using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; -using System.Threading; -using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CodeStyle; -using Microsoft.CodeAnalysis.CSharp.CodeStyle; using Microsoft.CodeAnalysis.CSharp.LanguageService; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.OrderModifiers; @@ -17,17 +14,13 @@ namespace Microsoft.CodeAnalysis.CSharp.OrderModifiers; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.OrderModifiers), Shared] -internal sealed class CSharpOrderModifiersCodeFixProvider : AbstractOrderModifiersCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpOrderModifiersCodeFixProvider() + : AbstractOrderModifiersCodeFixProvider(CSharpSyntaxFacts.Instance, CSharpOrderModifiersHelper.Instance) { private const string CS0267 = nameof(CS0267); // The 'partial' modifier can only appear immediately before 'class', 'record', 'struct', 'interface', or 'void' - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpOrderModifiersCodeFixProvider() - : base(CSharpSyntaxFacts.Instance, CSharpOrderModifiersHelper.Instance) - { - } - protected override CodeStyleOption2 GetCodeStyleOption(AnalyzerOptionsProvider options) => ((CSharpAnalyzerOptionsProvider)options).PreferredModifierOrder; From 12b9d00e851f7f6af4154d0365d7a26232bb3b07 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:54:49 -0700 Subject: [PATCH 37/98] Use primary constructors --- .../CSharpPopulateSwitchExpressionCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/PopulateSwitch/CSharpPopulateSwitchExpressionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/PopulateSwitch/CSharpPopulateSwitchExpressionCodeFixProvider.cs index b1691743e92e2..4ef787adcc086 100644 --- a/src/Analyzers/CSharp/CodeFixes/PopulateSwitch/CSharpPopulateSwitchExpressionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/PopulateSwitch/CSharpPopulateSwitchExpressionCodeFixProvider.cs @@ -18,19 +18,15 @@ namespace Microsoft.CodeAnalysis.CSharp.PopulateSwitch; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.PopulateSwitchExpression), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.ImplementInterface)] -internal class CSharpPopulateSwitchExpressionCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpPopulateSwitchExpressionCodeFixProvider() : AbstractPopulateSwitchExpressionCodeFixProvider< ExpressionSyntax, SwitchExpressionSyntax, SwitchExpressionArmSyntax, MemberAccessExpressionSyntax> { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpPopulateSwitchExpressionCodeFixProvider() - { - } - protected override SwitchExpressionArmSyntax CreateDefaultSwitchArm(SyntaxGenerator generator, Compilation compilation) => SwitchExpressionArm(DiscardPattern(), Exception(generator, compilation)); From 8ef545d66981c7b6adf80bd4ad1d3539f1a15498 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:55:05 -0700 Subject: [PATCH 38/98] Use primary constructors --- .../CSharpQualifyMemberAccessCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/QualifyMemberAccess/CSharpQualifyMemberAccessCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/QualifyMemberAccess/CSharpQualifyMemberAccessCodeFixProvider.cs index dd3003ee9a437..f6f075d708741 100644 --- a/src/Analyzers/CSharp/CodeFixes/QualifyMemberAccess/CSharpQualifyMemberAccessCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/QualifyMemberAccess/CSharpQualifyMemberAccessCodeFixProvider.cs @@ -14,14 +14,10 @@ namespace Microsoft.CodeAnalysis.CSharp.QualifyMemberAccess; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.QualifyMemberAccess), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.RemoveUnnecessaryCast)] -internal class CSharpQualifyMemberAccessCodeFixProvider : AbstractQualifyMemberAccessCodeFixprovider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpQualifyMemberAccessCodeFixProvider() : AbstractQualifyMemberAccessCodeFixprovider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpQualifyMemberAccessCodeFixProvider() - { - } - protected override SimpleNameSyntax? GetNode(Diagnostic diagnostic, CancellationToken cancellationToken) { var node = diagnostic.Location.FindNode(getInnermostNodeForTie: true, cancellationToken); From 3e6463edd0f6656ccd7a1bfdf6eccde00aee12c1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:55:22 -0700 Subject: [PATCH 39/98] Use primary constructors --- .../CSharpRemoveAsyncModifierCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveAsyncModifier/CSharpRemoveAsyncModifierCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveAsyncModifier/CSharpRemoveAsyncModifierCodeFixProvider.cs index 0a453ff0458ed..15e80e1eee832 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveAsyncModifier/CSharpRemoveAsyncModifierCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveAsyncModifier/CSharpRemoveAsyncModifierCodeFixProvider.cs @@ -19,16 +19,12 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveAsyncModifier; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveAsyncModifier), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.MakeMethodSynchronous)] -internal partial class CSharpRemoveAsyncModifierCodeFixProvider : AbstractRemoveAsyncModifierCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class CSharpRemoveAsyncModifierCodeFixProvider() : AbstractRemoveAsyncModifierCodeFixProvider { private const string CS1998 = nameof(CS1998); // This async method lacks 'await' operators and will run synchronously. - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpRemoveAsyncModifierCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS1998]; protected override bool IsAsyncSupportingFunctionSyntax(SyntaxNode node) From 8d3ccc1f540a44840959b4618034ea6b798d1c71 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:55:36 -0700 Subject: [PATCH 40/98] Use primary constructors --- .../CSharpRemoveConfusingSuppressionCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveConfusingSuppression/CSharpRemoveConfusingSuppressionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveConfusingSuppression/CSharpRemoveConfusingSuppressionCodeFixProvider.cs index daab59954822b..685d47fe4f6cb 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveConfusingSuppression/CSharpRemoveConfusingSuppressionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveConfusingSuppression/CSharpRemoveConfusingSuppressionCodeFixProvider.cs @@ -21,17 +21,13 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveConfusingSuppression; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveConfusingSuppression), Shared] -internal sealed partial class CSharpRemoveConfusingSuppressionCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed partial class CSharpRemoveConfusingSuppressionCodeFixProvider() : CodeFixProvider { public const string RemoveOperator = nameof(RemoveOperator); public const string NegateExpression = nameof(NegateExpression); - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpRemoveConfusingSuppressionCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.RemoveConfusingSuppressionForIsExpressionDiagnosticId]; From 246f074bed642c0f8491be2121043a0b979b2ed2 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:55:54 -0700 Subject: [PATCH 41/98] Use primary constructors --- .../RemoveInKeyword/RemoveInKeywordCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveInKeyword/RemoveInKeywordCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveInKeyword/RemoveInKeywordCodeFixProvider.cs index 8d1d8c756f031..4bab16a5e36b9 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveInKeyword/RemoveInKeywordCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveInKeyword/RemoveInKeywordCodeFixProvider.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -20,16 +19,12 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveInKeyword; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveIn), Shared] -internal class RemoveInKeywordCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class RemoveInKeywordCodeFixProvider() : CodeFixProvider { private const string CS1615 = nameof(CS1615); // Argument 1 may not be passed with the 'in' keyword - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public RemoveInKeywordCodeFixProvider() - { - } - public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; From 497ef27186a8a4658c94c485a65e14c6159df9b4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:56:08 -0700 Subject: [PATCH 42/98] Use primary constructors --- .../RemoveNewModifierCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveNewModifier/RemoveNewModifierCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveNewModifier/RemoveNewModifierCodeFixProvider.cs index 6fb3710f7ea06..6a0863a16dbc4 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveNewModifier/RemoveNewModifierCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveNewModifier/RemoveNewModifierCodeFixProvider.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -18,16 +17,12 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.RemoveNewModifier; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveNew), Shared] -internal class RemoveNewModifierCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class RemoveNewModifierCodeFixProvider() : CodeFixProvider { private const string CS0109 = nameof(CS0109); // The member 'SomeClass.SomeMember' does not hide an accessible member. The new keyword is not required. - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public RemoveNewModifierCodeFixProvider() - { - } - public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; From effb334a216bec657527f75d72ad07c23fed9dd0 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:56:22 -0700 Subject: [PATCH 43/98] Use primary constructors --- .../CSharpRemoveUnnecessaryCastCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs index 2b2a2f999063c..5c34ff12c9305 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs @@ -25,14 +25,10 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveUnnecessaryCast; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnnecessaryCast), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.ImplementInterface)] -internal partial class CSharpRemoveUnnecessaryCastCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class CSharpRemoveUnnecessaryCastCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpRemoveUnnecessaryCastCodeFixProvider() - { - } - public sealed override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.RemoveUnnecessaryCastDiagnosticId]; From 5f2852ecf334c9fa851de477dd2525c224d19379 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:56:35 -0700 Subject: [PATCH 44/98] Use primary constructors --- ...UnnecessaryDiscardDesignationCodeFixProvider.cs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryDiscardDesignation/CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryDiscardDesignation/CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider.cs index 14ae92e57b383..bb128253e29e2 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryDiscardDesignation/CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryDiscardDesignation/CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider.cs @@ -5,11 +5,8 @@ using System; using System.Collections.Immutable; using System.Composition; -using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; @@ -17,19 +14,14 @@ using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Shared.Extensions; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.RemoveUnnecessaryDiscardDesignation; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnnecessaryDiscardDesignation), Shared] -internal partial class CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed partial class CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.RemoveUnnecessaryDiscardDesignationDiagnosticId]; From dc24902a95461588f86a4be7b48900c59592bb28 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:56:53 -0700 Subject: [PATCH 45/98] Use primary constructors --- .../CSharpRemoveUnnecessaryImportsCodeFixProvider.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryImports/CSharpRemoveUnnecessaryImportsCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryImports/CSharpRemoveUnnecessaryImportsCodeFixProvider.cs index e1e0760dbc711..4afff26be42b2 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryImports/CSharpRemoveUnnecessaryImportsCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryImports/CSharpRemoveUnnecessaryImportsCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Composition; using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; @@ -15,14 +13,10 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveUnnecessaryImports; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnnecessaryImports), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.AddMissingReference)] -internal class CSharpRemoveUnnecessaryImportsCodeFixProvider : AbstractRemoveUnnecessaryImportsCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpRemoveUnnecessaryImportsCodeFixProvider() : AbstractRemoveUnnecessaryImportsCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpRemoveUnnecessaryImportsCodeFixProvider() - { - } - protected override string GetTitle() => CSharpCodeFixesResources.Remove_unnecessary_usings; From 3a091d3b2fc9bd6b704c4cd56cb78e3693d0a310 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:57:06 -0700 Subject: [PATCH 46/98] Use primary constructors --- ...oveUnnecessaryLambdaExpressionCodeFixProvider.cs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryLambdaExpression/CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryLambdaExpression/CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider.cs index 3eadd802378e5..d219c3bd03a0b 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryLambdaExpression/CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryLambdaExpression/CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider.cs @@ -5,10 +5,8 @@ using System; using System.Collections.Immutable; using System.Composition; -using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -16,21 +14,16 @@ using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Shared.Extensions; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.RemoveUnnecessaryLambdaExpression; using static CSharpRemoveUnnecessaryLambdaExpressionDiagnosticAnalyzer; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnnecessaryLambdaExpression), Shared] -internal partial class CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed partial class CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.RemoveUnnecessaryLambdaExpressionDiagnosticId]; From 81e6e6fc943d71ab0fa6866d415bb4eb7250b09a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:57:25 -0700 Subject: [PATCH 47/98] Use primary constructors --- ...pRemoveUnnecessaryParenthesesCodeFixProvider.cs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryParentheses/CSharpRemoveUnnecessaryParenthesesCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryParentheses/CSharpRemoveUnnecessaryParenthesesCodeFixProvider.cs index 204c4c17a38f3..bd7830b81c497 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryParentheses/CSharpRemoveUnnecessaryParenthesesCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryParentheses/CSharpRemoveUnnecessaryParenthesesCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Composition; using System.Diagnostics.CodeAnalysis; using System.Threading; @@ -14,15 +12,11 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveUnnecessaryParentheses; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnnecessaryParentheses), Shared] -internal class CSharpRemoveUnnecessaryParenthesesCodeFixProvider : - AbstractRemoveUnnecessaryParenthesesCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpRemoveUnnecessaryParenthesesCodeFixProvider() + : AbstractRemoveUnnecessaryParenthesesCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpRemoveUnnecessaryParenthesesCodeFixProvider() - { - } - protected override bool CanRemoveParentheses(SyntaxNode current, SemanticModel semanticModel, CancellationToken cancellationToken) => current switch { From 0d9c9611dfdbf4b77fccb36a8c7c15608618d667 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:57:39 -0700 Subject: [PATCH 48/98] Use primary constructors --- .../CSharpRemoveUnusedLocalFunctionCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedLocalFunction/CSharpRemoveUnusedLocalFunctionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedLocalFunction/CSharpRemoveUnusedLocalFunctionCodeFixProvider.cs index 1cf3df3dd320a..6fa5f28aa5519 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedLocalFunction/CSharpRemoveUnusedLocalFunctionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedLocalFunction/CSharpRemoveUnusedLocalFunctionCodeFixProvider.cs @@ -19,16 +19,12 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveUnusedLocalFunction; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnusedLocalFunction), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.AddImport)] -internal class CSharpRemoveUnusedLocalFunctionCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpRemoveUnusedLocalFunctionCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const string CS8321 = nameof(CS8321); // The local function 'X' is declared but never used - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpRemoveUnusedLocalFunctionCodeFixProvider() - { - } - public sealed override ImmutableArray FixableDiagnosticIds => [CS8321]; From 2e8d516f425048af948cf7e3c284e7a6b8086c82 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:57:58 -0700 Subject: [PATCH 49/98] Use primary constructors --- .../CSharpRemoveUnusedMembersCodeFixProvider.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedMembers/CSharpRemoveUnusedMembersCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedMembers/CSharpRemoveUnusedMembersCodeFixProvider.cs index a9d4d39ed68d7..5a22dd0173095 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedMembers/CSharpRemoveUnusedMembersCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedMembers/CSharpRemoveUnusedMembersCodeFixProvider.cs @@ -2,27 +2,21 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - +using System; using System.Collections.Generic; using System.Composition; -using Microsoft.CodeAnalysis.RemoveUnusedMembers; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; -using System; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.RemoveUnusedMembers; namespace Microsoft.CodeAnalysis.CSharp.RemoveUnusedMembers; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnusedMembers), Shared] -internal class CSharpRemoveUnusedMembersCodeFixProvider : AbstractRemoveUnusedMembersCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpRemoveUnusedMembersCodeFixProvider() : AbstractRemoveUnusedMembersCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpRemoveUnusedMembersCodeFixProvider() - { - } - /// /// This method adjusts the to remove based on whether or not all variable declarators /// within a field declaration should be removed, From 265a5ef3914747fb871b2d90decf1b5d5694bce9 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:58:18 -0700 Subject: [PATCH 50/98] Use primary constructors --- .../CSharpRemoveUnusedValuesCodeFixProvider.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs index d80b9b34b4eaa..0dc48ef3c9686 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs @@ -25,17 +25,13 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveUnusedParametersAndValues; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.RemoveUnusedValues), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.AddImport)] -internal class CSharpRemoveUnusedValuesCodeFixProvider : - AbstractRemoveUnusedValuesCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpRemoveUnusedValuesCodeFixProvider() - { - } - protected override ISyntaxFormatting GetSyntaxFormatting() => CSharpSyntaxFormatting.Instance; From a8670e8462b9a17bf35302828f9b5203ad3730ff Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:58:34 -0700 Subject: [PATCH 51/98] Use primary constructors --- .../CSharpReplaceDefaultLiteralCodeFixProvider.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/ReplaceDefaultLiteral/CSharpReplaceDefaultLiteralCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ReplaceDefaultLiteral/CSharpReplaceDefaultLiteralCodeFixProvider.cs index 5d042bc0fe210..c5ba3aa3475e7 100644 --- a/src/Analyzers/CSharp/CodeFixes/ReplaceDefaultLiteral/CSharpReplaceDefaultLiteralCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ReplaceDefaultLiteral/CSharpReplaceDefaultLiteralCodeFixProvider.cs @@ -20,19 +20,14 @@ namespace Microsoft.CodeAnalysis.CSharp.ReplaceDefaultLiteral; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ReplaceDefaultLiteral), Shared] -internal sealed class CSharpReplaceDefaultLiteralCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpReplaceDefaultLiteralCodeFixProvider() : CodeFixProvider { private const string CS8313 = nameof(CS8313); // A default literal 'default' is not valid as a case constant. Use another literal (e.g. '0' or 'null') as appropriate. If you intended to write the default label, use 'default:' without 'case'. private const string CS8505 = nameof(CS8505); // A default literal 'default' is not valid as a pattern. Use another literal (e.g. '0' or 'null') as appropriate. To match everything, use a discard pattern 'var _'. - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpReplaceDefaultLiteralCodeFixProvider() - { - } - - public override ImmutableArray FixableDiagnosticIds { get; } = - [CS8313, CS8505]; + public override ImmutableArray FixableDiagnosticIds { get; } = [CS8313, CS8505]; public override FixAllProvider? GetFixAllProvider() { From 7e5865ee4a48f63b767f6dbd25fbeb4feb2b4544 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:59:06 -0700 Subject: [PATCH 52/98] Use primary constructors --- .../CSharpRemoveUnnecessaryCastCodeFixProvider.cs | 3 --- .../CSharpSimplifyInterpolationCodeFixProvider.cs | 14 ++++---------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs index 5c34ff12c9305..726efeaf9df28 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs @@ -2,14 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Simplification.Simplifiers; diff --git a/src/Analyzers/CSharp/CodeFixes/SimplifyInterpolation/CSharpSimplifyInterpolationCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/SimplifyInterpolation/CSharpSimplifyInterpolationCodeFixProvider.cs index e701351b66dc5..7f8021ce4da77 100644 --- a/src/Analyzers/CSharp/CodeFixes/SimplifyInterpolation/CSharpSimplifyInterpolationCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/SimplifyInterpolation/CSharpSimplifyInterpolationCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Composition; using System.Diagnostics.CodeAnalysis; using System.Text; @@ -15,16 +13,12 @@ namespace Microsoft.CodeAnalysis.CSharp.SimplifyInterpolation; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.SimplifyInterpolation), Shared] -internal class CSharpSimplifyInterpolationCodeFixProvider : AbstractSimplifyInterpolationCodeFixProvider< +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpSimplifyInterpolationCodeFixProvider() : AbstractSimplifyInterpolationCodeFixProvider< InterpolationSyntax, ExpressionSyntax, InterpolationAlignmentClauseSyntax, InterpolationFormatClauseSyntax, InterpolatedStringExpressionSyntax> { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpSimplifyInterpolationCodeFixProvider() - { - } - protected override AbstractSimplifyInterpolationHelpers GetHelpers() => CSharpSimplifyInterpolationHelpers.Instance; protected override InterpolationSyntax WithExpression(InterpolationSyntax interpolation, ExpressionSyntax expression) @@ -33,7 +27,7 @@ protected override InterpolationSyntax WithExpression(InterpolationSyntax interp protected override InterpolationSyntax WithAlignmentClause(InterpolationSyntax interpolation, InterpolationAlignmentClauseSyntax alignmentClause) => interpolation.WithAlignmentClause(alignmentClause); - protected override InterpolationSyntax WithFormatClause(InterpolationSyntax interpolation, InterpolationFormatClauseSyntax formatClause) + protected override InterpolationSyntax WithFormatClause(InterpolationSyntax interpolation, InterpolationFormatClauseSyntax? formatClause) => interpolation.WithFormatClause(formatClause); protected override string Escape(InterpolatedStringExpressionSyntax interpolatedString, string formatString) From 664fc9ca36aed6f9d1ddfacd13020372e64ef94b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:59:19 -0700 Subject: [PATCH 53/98] Use primary constructors --- .../CSharpSimplifyLinqExpressionCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/SimplifyLinqExpression/CSharpSimplifyLinqExpressionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/SimplifyLinqExpression/CSharpSimplifyLinqExpressionCodeFixProvider.cs index 6d70c1b191fa6..ea9061d1df6eb 100644 --- a/src/Analyzers/CSharp/CodeFixes/SimplifyLinqExpression/CSharpSimplifyLinqExpressionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/SimplifyLinqExpression/CSharpSimplifyLinqExpressionCodeFixProvider.cs @@ -13,13 +13,9 @@ namespace Microsoft.CodeAnalysis.CSharp.SimplifyLinqExpression; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.SimplifyLinqExpression), Shared] -internal sealed class CSharpSimplifyLinqExpressionCodeFixProvider : AbstractSimplifyLinqExpressionCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpSimplifyLinqExpressionCodeFixProvider() : AbstractSimplifyLinqExpressionCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpSimplifyLinqExpressionCodeFixProvider() - { - } - protected override ISyntaxFacts SyntaxFacts => CSharpSyntaxFacts.Instance; } From 1434198db75fa325278254cecad03931ec944d9c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:59:36 -0700 Subject: [PATCH 54/98] Use primary constructors --- .../CSharpSimplifyPropertyPatternCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/SimplifyPropertyPattern/CSharpSimplifyPropertyPatternCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/SimplifyPropertyPattern/CSharpSimplifyPropertyPatternCodeFixProvider.cs index 894b5a51e583a..521cbb3b76809 100644 --- a/src/Analyzers/CSharp/CodeFixes/SimplifyPropertyPattern/CSharpSimplifyPropertyPatternCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/SimplifyPropertyPattern/CSharpSimplifyPropertyPatternCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; @@ -23,14 +22,10 @@ namespace Microsoft.CodeAnalysis.CSharp.SimplifyPropertyPattern; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.SimplifyPropertyPattern), Shared] -internal class CSharpSimplifyPropertyPatternCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpSimplifyPropertyPatternCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpSimplifyPropertyPatternCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.SimplifyPropertyPatternDiagnosticId]; From aa883b312f475fc9154c4560ae034cc902cb6d31 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 11:59:49 -0700 Subject: [PATCH 55/98] Use primary constructors --- .../CSharpTransposeRecordKeywordCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs index 2bd72a73938e3..e02c05bf0f381 100644 --- a/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editing; @@ -19,16 +18,12 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.TransposeRecordKeyword; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.TransposeRecordKeyword), Shared] -internal class CSharpTransposeRecordKeywordCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpTransposeRecordKeywordCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const string CS9012 = nameof(CS9012); // Unexpected keyword 'record'. Did you mean 'record struct' or 'record class'? - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpTransposeRecordKeywordCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [CS9012]; From 26f124dc73de77831b747498629adb490c025367 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:00:13 -0700 Subject: [PATCH 56/98] Use primary constructors --- .../CSharpTransposeRecordKeywordCodeFixProvider.cs | 3 +-- .../UnsealClass/CSharpUnsealClassCodeFixProvider.cs | 13 ++++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs index e02c05bf0f381..b9294d8b975de 100644 --- a/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs @@ -24,8 +24,7 @@ internal sealed class CSharpTransposeRecordKeywordCodeFixProvider() : SyntaxEdit { private const string CS9012 = nameof(CS9012); // Unexpected keyword 'record'. Did you mean 'record struct' or 'record class'? - public override ImmutableArray FixableDiagnosticIds - => [CS9012]; + public override ImmutableArray FixableDiagnosticIds => [CS9012]; private static bool TryGetRecordDeclaration( Diagnostic diagnostic, CancellationToken cancellationToken, [NotNullWhen(true)] out RecordDeclarationSyntax? recordDeclaration) diff --git a/src/Analyzers/CSharp/CodeFixes/UnsealClass/CSharpUnsealClassCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UnsealClass/CSharpUnsealClassCodeFixProvider.cs index fa04bf91c8e1f..24f9abc726fcd 100644 --- a/src/Analyzers/CSharp/CodeFixes/UnsealClass/CSharpUnsealClassCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UnsealClass/CSharpUnsealClassCodeFixProvider.cs @@ -12,18 +12,13 @@ namespace Microsoft.CodeAnalysis.CSharp.UnsealClass; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UnsealClass), Shared] -internal sealed class CSharpUnsealClassCodeFixProvider : AbstractUnsealClassCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUnsealClassCodeFixProvider() : AbstractUnsealClassCodeFixProvider { private const string CS0509 = nameof(CS0509); // 'D': cannot derive from sealed type 'C' - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUnsealClassCodeFixProvider() - { - } - - public override ImmutableArray FixableDiagnosticIds { get; } = - [CS0509]; + public override ImmutableArray FixableDiagnosticIds { get; } = [CS0509]; protected override string TitleFormat => CSharpCodeFixesResources.Unseal_class_0; } From fdbea4cf890351d2747d4d174c938e3f7a85a689 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:00:27 -0700 Subject: [PATCH 57/98] Use primary constructors --- .../CSharpUpdateProjectToAllowUnsafeCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UpdateProjectToAllowUnsafe/CSharpUpdateProjectToAllowUnsafeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UpdateProjectToAllowUnsafe/CSharpUpdateProjectToAllowUnsafeCodeFixProvider.cs index 5cc5d41e433ad..4c7fe2d7c1435 100644 --- a/src/Analyzers/CSharp/CodeFixes/UpdateProjectToAllowUnsafe/CSharpUpdateProjectToAllowUnsafeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UpdateProjectToAllowUnsafe/CSharpUpdateProjectToAllowUnsafeCodeFixProvider.cs @@ -13,16 +13,12 @@ namespace Microsoft.CodeAnalysis.CSharp.UpdateProjectToAllowUnsafe; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UpdateProjectToAllowUnsafe), Shared] -internal class CSharpUpdateProjectToAllowUnsafeCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUpdateProjectToAllowUnsafeCodeFixProvider() : CodeFixProvider { private const string CS0227 = nameof(CS0227); // error CS0227: Unsafe code may only appear if compiling with /unsafe - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUpdateProjectToAllowUnsafeCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS0227]; From 4df2a2cab800053ecaac09b720458e13d5cede2d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:00:43 -0700 Subject: [PATCH 58/98] Use primary constructors --- .../CSharpUpgradeProjectCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UpgradeProject/CSharpUpgradeProjectCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UpgradeProject/CSharpUpgradeProjectCodeFixProvider.cs index fcdabb3ea4274..f76ddccb4aa3f 100644 --- a/src/Analyzers/CSharp/CodeFixes/UpgradeProject/CSharpUpgradeProjectCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UpgradeProject/CSharpUpgradeProjectCodeFixProvider.cs @@ -13,14 +13,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UpgradeProject; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UpgradeProject), Shared] -internal class CSharpUpgradeProjectCodeFixProvider : AbstractUpgradeProjectCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUpgradeProjectCodeFixProvider() : AbstractUpgradeProjectCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUpgradeProjectCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [ "CS8022", From 74d9187a2e7997f3f28b7c9ce37300a04f7d40c8 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:01:02 -0700 Subject: [PATCH 59/98] Use primary constructors --- .../CSharpUseCompoundAssignmentCodeFixProvider.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundAssignmentCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundAssignmentCodeFixProvider.cs index 1539083103c96..a2d4a0770d575 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundAssignmentCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundAssignmentCodeFixProvider.cs @@ -14,16 +14,11 @@ namespace Microsoft.CodeAnalysis.CSharp.UseCompoundAssignment; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseCompoundAssignment), Shared] -internal class CSharpUseCompoundAssignmentCodeFixProvider - : AbstractUseCompoundAssignmentCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUseCompoundAssignmentCodeFixProvider() + : AbstractUseCompoundAssignmentCodeFixProvider(Utilities.Kinds) { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseCompoundAssignmentCodeFixProvider() - : base(Utilities.Kinds) - { - } - protected override SyntaxToken Token(SyntaxKind kind) => SyntaxFactory.Token(kind); From 8ff8463481603faa581a65006df1005b01119b9d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:01:19 -0700 Subject: [PATCH 60/98] Use primary constructors --- ...harpUseCompoundCoalesceAssignmentCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs index de964491ae666..761e8ec9d335d 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs @@ -25,14 +25,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseCompoundAssignment; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseCompoundCoalesceAssignment), Shared] -internal class CSharpUseCompoundCoalesceAssignmentCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUseCompoundCoalesceAssignmentCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseCompoundCoalesceAssignmentCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseCoalesceCompoundAssignmentDiagnosticId]; From ad8806a3445bcdd32b6050edd73971e7a8a2481e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:01:34 -0700 Subject: [PATCH 61/98] Use primary constructors --- ...UseConditionalExpressionForReturnCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForReturnCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForReturnCodeFixProvider.cs index f92caeab2fe45..ba4a932007522 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForReturnCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/CSharpUseConditionalExpressionForReturnCodeFixProvider.cs @@ -17,15 +17,11 @@ namespace Microsoft.CodeAnalysis.CSharp.UseConditionalExpression; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseConditionalExpressionForReturn), Shared] -internal partial class CSharpUseConditionalExpressionForReturnCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class CSharpUseConditionalExpressionForReturnCodeFixProvider() : AbstractUseConditionalExpressionForReturnCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseConditionalExpressionForReturnCodeFixProvider() - { - } - protected override ISyntaxFacts SyntaxFacts => CSharpSyntaxFacts.Instance; From 673f12797bc6b918ef8387bd927cde437c7e66cd Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:01:49 -0700 Subject: [PATCH 62/98] Use primary constructors --- .../CSharpUseDeconstructionCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs index 202e5e056442c..2ffc570085015 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs @@ -10,7 +10,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -24,14 +23,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseDeconstruction; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseDeconstruction), Shared] -internal sealed class CSharpUseDeconstructionCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUseDeconstructionCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseDeconstructionCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseDeconstructionDiagnosticId]; From d2e09e182bf6ec3cb2415d24c87802faea9d4900 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:02:01 -0700 Subject: [PATCH 63/98] Use primary constructors --- .../CSharpUseDefaultLiteralCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseDefaultLiteral/CSharpUseDefaultLiteralCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseDefaultLiteral/CSharpUseDefaultLiteralCodeFixProvider.cs index f181a58a5be65..880a706cd682c 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseDefaultLiteral/CSharpUseDefaultLiteralCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseDefaultLiteral/CSharpUseDefaultLiteralCodeFixProvider.cs @@ -7,7 +7,6 @@ using System.Composition; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -19,14 +18,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseDefaultLiteral; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseDefaultLiteral), Shared] -internal partial class CSharpUseDefaultLiteralCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed partial class CSharpUseDefaultLiteralCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseDefaultLiteralCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseDefaultLiteralDiagnosticId]; From ff189f2496b9a72e3647b3fde579118c91b281af Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:02:15 -0700 Subject: [PATCH 64/98] Use primary constructors --- .../UseExplicitTypeForConstCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseExplicitTypeForConst/UseExplicitTypeForConstCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseExplicitTypeForConst/UseExplicitTypeForConstCodeFixProvider.cs index 18f715432edf0..be2159b0fecd3 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseExplicitTypeForConst/UseExplicitTypeForConstCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseExplicitTypeForConst/UseExplicitTypeForConstCodeFixProvider.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -18,16 +17,12 @@ namespace Microsoft.CodeAnalysis.CSharp.UseExplicitTypeForConst; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseExplicitTypeForConst), Shared] -internal sealed class UseExplicitTypeForConstCodeFixProvider : CodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class UseExplicitTypeForConstCodeFixProvider() : CodeFixProvider { private const string CS0822 = nameof(CS0822); // Implicitly-typed variables cannot be constant - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public UseExplicitTypeForConstCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [CS0822]; public override FixAllProvider? GetFixAllProvider() From 871910ea27b1f0b6aa6f978615e8ff19791c912f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:02:42 -0700 Subject: [PATCH 65/98] Use primary constructors --- .../UseExpressionBodyForLambdaCodeFixProvider.cs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeFixProvider.cs index 3b51259a77378..7cc54114e6761 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeFixProvider.cs @@ -5,31 +5,23 @@ using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CodeStyle; using Microsoft.CodeAnalysis.CSharp.CodeFixes.UseExpressionBodyForLambda; -using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editing; -using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Shared.Extensions; namespace Microsoft.CodeAnalysis.CSharp.UseExpressionBodyForLambda; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseExpressionBodyForLambda), Shared] -internal sealed class UseExpressionBodyForLambdaCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class UseExpressionBodyForLambdaCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public UseExpressionBodyForLambdaCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseExpressionBodyForLambdaExpressionsDiagnosticId]; public override Task RegisterCodeFixesAsync(CodeFixContext context) From 8d35f5eb33ba38dee8b779a8f123137ea6d82af5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:02:59 -0700 Subject: [PATCH 66/98] Use primary constructors --- ...SharpUseImplicitObjectCreationCodeFixProvider.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseImplicitObjectCreation/CSharpUseImplicitObjectCreationCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseImplicitObjectCreation/CSharpUseImplicitObjectCreationCodeFixProvider.cs index 453c9ed5f7092..6bc18e8e3d139 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseImplicitObjectCreation/CSharpUseImplicitObjectCreationCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseImplicitObjectCreation/CSharpUseImplicitObjectCreationCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Simplification; @@ -22,18 +21,14 @@ namespace Microsoft.CodeAnalysis.CSharp.UseImplicitObjectCreation; -using static SyntaxFactory; using static CSharpUseImplicitObjectCreationDiagnosticAnalyzer; +using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseImplicitObjectCreation), Shared] -internal class CSharpUseImplicitObjectCreationCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUseImplicitObjectCreationCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseImplicitObjectCreationCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseImplicitObjectCreationDiagnosticId]; From 4fb8645996580c53ac73596ad8583b755663e9cc Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:03:13 -0700 Subject: [PATCH 67/98] Use primary constructors --- .../UseExplicitTypeCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs index 7ae79431b5afb..d1102e6abb8fe 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs @@ -26,14 +26,10 @@ namespace Microsoft.CodeAnalysis.CSharp.TypeStyle; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseExplicitType), Shared] -internal class UseExplicitTypeCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class UseExplicitTypeCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public UseExplicitTypeCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseExplicitTypeDiagnosticId]; From 5b52d3a10ee548e7027727ce687c7c017fa19177 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:03:27 -0700 Subject: [PATCH 68/98] Use primary constructors --- .../UseImplicitTypeCodeFixProvider.cs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs index 7d443979d010c..a510ac49a46af 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs @@ -4,32 +4,24 @@ #nullable disable -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editing; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.TypeStyle; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseImplicitType), Shared] -internal class UseImplicitTypeCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class UseImplicitTypeCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public UseImplicitTypeCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseImplicitTypeDiagnosticId]; From ecd96b6755d42b3e321e9d15b5ab1bd5d71e4f35 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:03:40 -0700 Subject: [PATCH 69/98] Use primary constructors --- .../CSharpUseIndexOperatorCodeFixProvider.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs index 16429204d2f7f..e96ac33c3be9e 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs @@ -4,13 +4,11 @@ #nullable disable -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; @@ -23,14 +21,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseIndexOrRangeOperator; using static CodeFixHelpers; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseIndexOperator), Shared] -internal class CSharpUseIndexOperatorCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUseIndexOperatorCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseIndexOperatorCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseIndexOperatorDiagnosticId]; From 022d31e5d8c4514731592610007fd7f21b9de59c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:03:53 -0700 Subject: [PATCH 70/98] Use primary constructors --- .../CSharpUseRangeOperatorCodeFixProvider.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseRangeOperatorCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseRangeOperatorCodeFixProvider.cs index ae163dd59f6f9..493607317a70b 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseRangeOperatorCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseRangeOperatorCodeFixProvider.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -24,20 +23,16 @@ namespace Microsoft.CodeAnalysis.CSharp.UseIndexOrRangeOperator; using static CodeFixHelpers; -using static CSharpUseRangeOperatorDiagnosticAnalyzer; using static CSharpSyntaxTokens; +using static CSharpUseRangeOperatorDiagnosticAnalyzer; using static Helpers; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseRangeOperator), Shared] -internal class CSharpUseRangeOperatorCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUseRangeOperatorCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseRangeOperatorCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseRangeOperatorDiagnosticId]; From 9733a3e9fad3baace33ec889780f9f96a046259f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:04:10 -0700 Subject: [PATCH 71/98] Use primary constructors --- .../CSharpUseInferredMemberNameCodeFixProvider.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseInferredMemberName/CSharpUseInferredMemberNameCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseInferredMemberName/CSharpUseInferredMemberNameCodeFixProvider.cs index e9870962cfc1b..8cbfb46647a21 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseInferredMemberName/CSharpUseInferredMemberNameCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseInferredMemberName/CSharpUseInferredMemberNameCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Composition; using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; @@ -13,14 +11,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseInferredMemberName; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseInferredMemberName), Shared] -internal sealed class CSharpUseInferredMemberNameCodeFixProvider : AbstractUseInferredMemberNameCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUseInferredMemberNameCodeFixProvider() : AbstractUseInferredMemberNameCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseInferredMemberNameCodeFixProvider() - { - } - protected override void LanguageSpecificRemoveSuggestedNode(SyntaxEditor editor, SyntaxNode node) => editor.RemoveNode(node, SyntaxRemoveOptions.KeepExteriorTrivia | SyntaxRemoveOptions.AddElasticMarker); } From 528802d28112571e02448f61b3c0e4651fa449c9 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:04:31 -0700 Subject: [PATCH 72/98] Use primary constructors --- ...InterpolatedVerbatimStringCodeFixProvider.cs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs index e6f9c13a3b0ee..2b634f752f0a8 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs @@ -4,19 +4,15 @@ #nullable disable -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Shared.Extensions; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.UseInterpolatedVerbatimString; @@ -24,16 +20,11 @@ namespace Microsoft.CodeAnalysis.CSharp.UseInterpolatedVerbatimString; /// Converts a verbatim interpolated string @$"" to an interpolated verbatim string $@"" /// [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseInterpolatedVerbatimString), Shared] -internal partial class CSharpUseInterpolatedVerbatimStringCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class CSharpUseInterpolatedVerbatimStringCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseInterpolatedVerbatimStringCodeFixProvider() - { - } - - public override ImmutableArray FixableDiagnosticIds - => ["CS8401"]; + public override ImmutableArray FixableDiagnosticIds => ["CS8401"]; private const string InterpolatedVerbatimText = "$@\""; From eeb97d229684385b63d27309efdfe6f8d398dcf5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:04:47 -0700 Subject: [PATCH 73/98] Use primary constructors --- ...lCheckForCastAndEqualityOperatorCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs index 8b0f7f4352440..905e130f7c7b8 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -25,14 +24,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseIsNullCheck; using static UseIsNullCheckHelpers; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseIsNullCheckForCastAndEqualityOperator), Shared] -internal class CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal class CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseIsNullCheckDiagnosticId]; From 3be1f895f4382dfafe4ed7b26acea507ecdfe266 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:05:03 -0700 Subject: [PATCH 74/98] Use primary constructors --- ...pUseIsNullCheckForReferenceEqualsCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs index 94f65c24eb81a..bb171c480ea1a 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs @@ -18,7 +18,9 @@ namespace Microsoft.CodeAnalysis.CSharp.UseIsNullCheck; using static UseIsNullCheckHelpers; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseIsNullCheckForReferenceEquals), Shared] -internal class CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal class CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider() : AbstractUseIsNullCheckForReferenceEqualsCodeFixProvider { private static readonly LiteralExpressionSyntax s_nullLiteralExpression @@ -27,12 +29,6 @@ private static readonly LiteralExpressionSyntax s_nullLiteralExpression private static readonly ConstantPatternSyntax s_nullLiteralPattern = ConstantPattern(s_nullLiteralExpression); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider() - { - } - protected override string GetTitle(bool negated, ParseOptions options) => UseIsNullCheckHelpers.GetTitle(negated, options); From da96f4cc31ab007a9d0fed30b400d8471d799b82 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:07:51 -0700 Subject: [PATCH 75/98] Use primary constructors --- .../CSharpDisambiguateSameVariableCodeFixProvider.cs | 3 +-- .../CSharpFixIncorrectConstraintCodeFixProvider.cs | 3 +-- .../CSharpChangeToIEnumerableCodeFixProvider.cs | 2 +- .../CSharpMakeMemberRequiredCodeFixProvider.cs | 3 +-- ...rpUseCompoundCoalesceAssignmentCodeFixProvider.cs | 1 - .../UseExplicitTypeCodeFixProvider.cs | 2 -- ...CheckForCastAndEqualityOperatorCodeFixProvider.cs | 2 +- ...seIsNullCheckForReferenceEqualsCodeFixProvider.cs | 2 +- ...CSharpUseNullCheckOverTypeCheckCodeFixProvider.cs | 12 +++--------- .../CSharpUseLocalFunctionCodeFixProvider.cs | 11 +++-------- 10 files changed, 12 insertions(+), 29 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs index f5c0e279aee6c..ec24c4ed1a0ee 100644 --- a/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs @@ -32,8 +32,7 @@ internal sealed class CSharpDisambiguateSameVariableCodeFixProvider() : SyntaxEd private const string CS1717 = nameof(CS1717); // Assignment made to same variable; did you mean to assign something else? private const string CS1718 = nameof(CS1718); // Comparison made to same variable; did you mean to compare something else? - public override ImmutableArray FixableDiagnosticIds { get; } - = [CS1717, CS1718]; + public override ImmutableArray FixableDiagnosticIds { get; } = [CS1717, CS1718]; public override async Task RegisterCodeFixesAsync(CodeFixContext context) { diff --git a/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs index e3fc27020e1e8..f49ac21d07316 100644 --- a/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs @@ -25,8 +25,7 @@ internal sealed class CSharpFixIncorrectConstraintCodeFixProvider() : SyntaxEdit private const string CS9010 = nameof(CS9010); // Keyword 'enum' cannot be used as a constraint.Did you mean 'struct, System.Enum'? Net6 C:\github\repo_find_refs\Net6\Class1.cs 1 Active private const string CS9011 = nameof(CS9011); // 'delegate' cannot be used as a constraint.Did you mean 'System.Delegate'? Net6 C:\github\repo_find_refs\Net6\Class1.cs 1 Active - public override ImmutableArray FixableDiagnosticIds - => [CS9010, CS9011]; + public override ImmutableArray FixableDiagnosticIds => [CS9010, CS9011]; private static bool TryGetConstraint( Diagnostic diagnostic, diff --git a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs index 63e5af1308a06..7f62a82ff0a1a 100644 --- a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs @@ -23,7 +23,7 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.Iterator; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ChangeReturnType), Shared] [method: ImportingConstructor] [method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] -internal class CSharpChangeToIEnumerableCodeFixProvider() : AbstractIteratorCodeFixProvider +internal sealed class CSharpChangeToIEnumerableCodeFixProvider() : AbstractIteratorCodeFixProvider { /// /// CS1624: The body of 'x' cannot be an iterator block because 'y' is not an iterator interface type diff --git a/src/Analyzers/CSharp/CodeFixes/MakeMemberRequired/CSharpMakeMemberRequiredCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeMemberRequired/CSharpMakeMemberRequiredCodeFixProvider.cs index 3cbf78f745f56..457ed7d684699 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeMemberRequired/CSharpMakeMemberRequiredCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeMemberRequired/CSharpMakeMemberRequiredCodeFixProvider.cs @@ -27,8 +27,7 @@ internal sealed class CSharpMakeMemberRequiredCodeFixProvider() : SyntaxEditorBa { private const string CS8618 = nameof(CS8618); // Non-nullable variable must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring it as nullable. - public override ImmutableArray FixableDiagnosticIds { get; } = - [CS8618]; + public override ImmutableArray FixableDiagnosticIds { get; } = [CS8618]; public override async Task RegisterCodeFixesAsync(CodeFixContext context) { diff --git a/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs index 761e8ec9d335d..a9ec9d8f034e8 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; diff --git a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs index d1102e6abb8fe..6bbaee842ad75 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics; @@ -10,7 +9,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; diff --git a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs index 905e130f7c7b8..2cc538d91b2c4 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs @@ -26,7 +26,7 @@ namespace Microsoft.CodeAnalysis.CSharp.UseIsNullCheck; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseIsNullCheckForCastAndEqualityOperator), Shared] [method: ImportingConstructor] [method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] -internal class CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider() : SyntaxEditorBasedCodeFixProvider +internal sealed class CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseIsNullCheckDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs index bb171c480ea1a..d342aed3dda21 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs @@ -20,7 +20,7 @@ namespace Microsoft.CodeAnalysis.CSharp.UseIsNullCheck; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseIsNullCheckForReferenceEquals), Shared] [method: ImportingConstructor] [method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] -internal class CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider() +internal sealed class CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider() : AbstractUseIsNullCheckForReferenceEqualsCodeFixProvider { private static readonly LiteralExpressionSyntax s_nullLiteralExpression diff --git a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseNullCheckOverTypeCheckCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseNullCheckOverTypeCheckCodeFixProvider.cs index 9e8d38a5f5f36..5c49751d76deb 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseNullCheckOverTypeCheckCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseNullCheckOverTypeCheckCodeFixProvider.cs @@ -5,10 +5,8 @@ using System; using System.Collections.Immutable; using System.Composition; -using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; @@ -22,16 +20,12 @@ namespace Microsoft.CodeAnalysis.CSharp.UseIsNullCheck; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseNullCheckOverTypeCheck), Shared] -internal sealed class CSharpUseNullCheckOverTypeCheckCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUseNullCheckOverTypeCheckCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private static readonly ConstantPatternSyntax s_nullConstantPattern = ConstantPattern(LiteralExpression(SyntaxKind.NullLiteralExpression)); - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseNullCheckOverTypeCheckCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseNullCheckOverTypeCheckDiagnosticId]; diff --git a/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs index 233060a239f19..931722e8eb838 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs @@ -12,7 +12,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CodeGeneration; using Microsoft.CodeAnalysis.CSharp.CodeGeneration; @@ -31,16 +30,12 @@ namespace Microsoft.CodeAnalysis.CSharp.UseLocalFunction; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseLocalFunction), Shared] -internal class CSharpUseLocalFunctionCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUseLocalFunctionCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private static readonly TypeSyntax s_objectType = PredefinedType(ObjectKeyword); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseLocalFunctionCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseLocalFunctionDiagnosticId]; From e5af26c2bbb6bc56ed6ae958dae9418e53451896 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:08:11 -0700 Subject: [PATCH 76/98] Use primary constructors --- .../CSharpUseNameofInAttributeCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseNameofInAttribute/CSharpUseNameofInAttributeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseNameofInAttribute/CSharpUseNameofInAttributeCodeFixProvider.cs index 4f4ecf47dbc53..56a91d73f3a41 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseNameofInAttribute/CSharpUseNameofInAttributeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseNameofInAttribute/CSharpUseNameofInAttributeCodeFixProvider.cs @@ -7,7 +7,6 @@ using System.Composition; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.UseNameofInAttribute; using Microsoft.CodeAnalysis.Diagnostics; @@ -19,14 +18,10 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.UseNameofInAttribute; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseNameofInAttribute), Shared] -internal sealed class CSharpUseNameofInAttributeCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUseNameofInAttributeCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseNameofInAttributeCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseNameofInAttributeDiagnosticId]; public override Task RegisterCodeFixesAsync(CodeFixContext context) From d3699bb483d6c870c19e65c8cee61d1c77c79336 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:08:27 -0700 Subject: [PATCH 77/98] Use primary constructors --- .../CSharpUseNullPropagationCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseNullPropagation/CSharpUseNullPropagationCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseNullPropagation/CSharpUseNullPropagationCodeFixProvider.cs index 43774aabce8e5..84b3074c92ac6 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseNullPropagation/CSharpUseNullPropagationCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseNullPropagation/CSharpUseNullPropagationCodeFixProvider.cs @@ -12,7 +12,9 @@ namespace Microsoft.CodeAnalysis.CSharp.UseNullPropagation; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseNullPropagation), Shared] -internal class CSharpUseNullPropagationCodeFixProvider : AbstractUseNullPropagationCodeFixProvider< +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUseNullPropagationCodeFixProvider() : AbstractUseNullPropagationCodeFixProvider< SyntaxKind, ExpressionSyntax, StatementSyntax, @@ -27,12 +29,6 @@ internal class CSharpUseNullPropagationCodeFixProvider : AbstractUseNullPropagat ExpressionStatementSyntax, BracketedArgumentListSyntax> { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseNullPropagationCodeFixProvider() - { - } - protected override bool TryGetBlock(SyntaxNode? statement, [NotNullWhen(true)] out StatementSyntax? block) { if (statement is BlockSyntax statementBlock) From 822261ed9b41d47bb1d09e4cac7dc94fea090d4a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:08:47 -0700 Subject: [PATCH 78/98] Use primary constructors --- .../CSharpUseObjectInitializerCodeFixProvider.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseObjectInitializer/CSharpUseObjectInitializerCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseObjectInitializer/CSharpUseObjectInitializerCodeFixProvider.cs index c096ad0701ea7..04467a74c3815 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseObjectInitializer/CSharpUseObjectInitializerCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseObjectInitializer/CSharpUseObjectInitializerCodeFixProvider.cs @@ -17,7 +17,9 @@ namespace Microsoft.CodeAnalysis.CSharp.UseObjectInitializer; using ObjectInitializerMatch = Match; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseObjectInitializer), Shared] -internal sealed class CSharpUseObjectInitializerCodeFixProvider : +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUseObjectInitializerCodeFixProvider() : AbstractUseObjectInitializerCodeFixProvider< SyntaxKind, ExpressionSyntax, @@ -29,12 +31,6 @@ internal sealed class CSharpUseObjectInitializerCodeFixProvider : VariableDeclaratorSyntax, CSharpUseNamedMemberInitializerAnalyzer> { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUseObjectInitializerCodeFixProvider() - { - } - protected override CSharpUseNamedMemberInitializerAnalyzer GetAnalyzer() => CSharpUseNamedMemberInitializerAnalyzer.Allocate(); From ad8b965346e5b2047ce7f55fd4da8af535c4edac Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:09:16 -0700 Subject: [PATCH 79/98] Use primary constructors --- .../CSharpUsePatternCombinatorsCodeFixProvider.cs | 14 ++++---------- .../CSharpAsAndMemberAccessCodeFixProvider.cs | 11 +++-------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs index c5f2bdfd401d3..e77d07be2fd57 100644 --- a/src/Analyzers/CSharp/CodeFixes/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs @@ -2,10 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; @@ -24,21 +22,17 @@ namespace Microsoft.CodeAnalysis.CSharp.UsePatternCombinators; -using static SyntaxFactory; using static AnalyzedPattern; +using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UsePatternCombinators), Shared] -internal class CSharpUsePatternCombinatorsCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class CSharpUsePatternCombinatorsCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const string SafeEquivalenceKey = nameof(CSharpUsePatternCombinatorsCodeFixProvider) + "_safe"; private const string UnsafeEquivalenceKey = nameof(CSharpUsePatternCombinatorsCodeFixProvider) + "_unsafe"; - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpUsePatternCombinatorsCodeFixProvider() - { - } - private static SyntaxKind MapToSyntaxKind(BinaryOperatorKind kind) { return kind switch diff --git a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndMemberAccessCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndMemberAccessCodeFixProvider.cs index 0b98dabe808a6..a148b464e4ead 100644 --- a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndMemberAccessCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndMemberAccessCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -24,14 +23,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UsePatternMatching; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UsePatternMatchingAsAndMemberAccess), Shared] -internal partial class CSharpAsAndMemberAccessCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed partial class CSharpAsAndMemberAccessCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpAsAndMemberAccessCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UsePatternMatchingAsAndMemberAccessDiagnosticId]; From 7223f6170579e5c061ec9470207128d0bf8f442e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:09:32 -0700 Subject: [PATCH 80/98] Use primary constructors --- .../CSharpAsAndNullCheckCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndNullCheckCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndNullCheckCodeFixProvider.cs index 6844779691092..c46ae30e09d37 100644 --- a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndNullCheckCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndNullCheckCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -24,14 +23,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UsePatternMatching; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UsePatternMatchingAsAndNullCheck), Shared] -internal partial class CSharpAsAndNullCheckCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class CSharpAsAndNullCheckCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpAsAndNullCheckCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.InlineAsTypeCheckId]; From 35a8a3d21cb5e2b38501d1796d650296347e3b01 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:09:53 -0700 Subject: [PATCH 81/98] Use primary constructors --- .../CSharpIsAndCastCheckCodeFixProvider.cs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpIsAndCastCheckCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpIsAndCastCheckCodeFixProvider.cs index bbf9084d3e89d..d234b3148fd34 100644 --- a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpIsAndCastCheckCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpIsAndCastCheckCodeFixProvider.cs @@ -2,16 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -24,14 +20,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UsePatternMatching; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UsePatternMatchingIsAndCastCheck), Shared] -internal partial class CSharpIsAndCastCheckCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class CSharpIsAndCastCheckCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public CSharpIsAndCastCheckCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.InlineIsTypeCheckId]; From a6697c563df937d451592900b08746d1e75d9c86 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:10:08 -0700 Subject: [PATCH 82/98] Use primary constructors --- .../CSharpUseNotPatternCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpUseNotPatternCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpUseNotPatternCodeFixProvider.cs index 4f10d8cdcad1d..1a3f54bbdcb20 100644 --- a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpUseNotPatternCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpUseNotPatternCodeFixProvider.cs @@ -7,7 +7,6 @@ using System.Composition; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.CodeGeneration; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -19,14 +18,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UsePatternMatching; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseNotPattern), Shared] -internal sealed class CSharpUseNotPatternCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpUseNotPatternCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseNotPatternCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseNotPatternDiagnosticId]; From a262a42fa3789215b2aa193da0d9be748466cded Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:10:31 -0700 Subject: [PATCH 83/98] Use primary constructors --- .../UseSimpleUsingStatementCodeFixProvider.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs index 74953322bd152..f2feec8761fe0 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs @@ -8,11 +8,9 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; -using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.LanguageService; @@ -31,14 +29,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseSimpleUsingStatement; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseSimpleUsingStatement), Shared] -internal class UseSimpleUsingStatementCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class UseSimpleUsingStatementCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public UseSimpleUsingStatementCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseSimpleUsingStatementDiagnosticId]; From 015817100f98fc44e4ed3b7226286a785dfe4cd6 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:10:47 -0700 Subject: [PATCH 84/98] Use primary constructors --- .../UseThrowExpressionCodeFixProvider.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseThrowExpression/UseThrowExpressionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseThrowExpression/UseThrowExpressionCodeFixProvider.cs index ce4845dc99f36..598b1cdca3762 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseThrowExpression/UseThrowExpressionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseThrowExpression/UseThrowExpressionCodeFixProvider.cs @@ -2,14 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -22,14 +20,10 @@ namespace Microsoft.CodeAnalysis.CSharp.UseThrowExpression; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseThrowExpression), Shared] -internal partial class UseThrowExpressionCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed partial class UseThrowExpressionCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public UseThrowExpressionCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds => [IDEDiagnosticIds.UseThrowExpressionDiagnosticId]; From 49feaa669ff844ff44d5e416db6ae8752241c00e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:11:01 -0700 Subject: [PATCH 85/98] Use primary constructors --- .../CSharpUseTupleSwapCodeFixProvider.cs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseTupleSwap/CSharpUseTupleSwapCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseTupleSwap/CSharpUseTupleSwapCodeFixProvider.cs index 1435cb8ad5c8a..deff3bf44e9f2 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseTupleSwap/CSharpUseTupleSwapCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseTupleSwap/CSharpUseTupleSwapCodeFixProvider.cs @@ -5,11 +5,8 @@ using System; using System.Collections.Immutable; using System.Composition; -using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -17,21 +14,16 @@ using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Shared.Extensions; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.UseTupleSwap; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseTupleSwap), Shared] -internal partial class CSharpUseTupleSwapCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed partial class CSharpUseTupleSwapCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpUseTupleSwapCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseTupleSwapDiagnosticId]; From f051ba712d89c325293ac56781f5aa00e2e5a4dc Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:11:15 -0700 Subject: [PATCH 86/98] Use primary constructors --- .../UseUtf8StringLiteralCodeFixProvider.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseUtf8StringLiteral/UseUtf8StringLiteralCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseUtf8StringLiteral/UseUtf8StringLiteralCodeFixProvider.cs index 3a241ce78237a..f82a29f839e6e 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseUtf8StringLiteral/UseUtf8StringLiteralCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseUtf8StringLiteral/UseUtf8StringLiteralCodeFixProvider.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; @@ -24,17 +23,13 @@ namespace Microsoft.CodeAnalysis.CSharp.UseUtf8StringLiteral; using static SyntaxFactory; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseUtf8StringLiteral), Shared] -internal sealed class UseUtf8StringLiteralCodeFixProvider : SyntaxEditorBasedCodeFixProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class UseUtf8StringLiteralCodeFixProvider() : SyntaxEditorBasedCodeFixProvider { private const char QuoteCharacter = '"'; private const string Suffix = "u8"; - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public UseUtf8StringLiteralCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds { get; } = [IDEDiagnosticIds.UseUtf8StringLiteralDiagnosticId]; From ecd915cae67f76c50f843b4d964c4e5733ce6d8b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:12:37 -0700 Subject: [PATCH 87/98] Add nrt support --- .../AddParameter/CSharpAddParameterCodeFixProvider.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/AddParameter/CSharpAddParameterCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AddParameter/CSharpAddParameterCodeFixProvider.cs index 715604c917b58..0325a7d6da94b 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddParameter/CSharpAddParameterCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddParameter/CSharpAddParameterCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -48,14 +46,14 @@ protected override ImmutableArray CannotConvertDiagnosticIds protected override ITypeSymbol GetArgumentType(SyntaxNode argumentNode, SemanticModel semanticModel, CancellationToken cancellationToken) => ((ArgumentSyntax)argumentNode).DetermineParameterType(semanticModel, cancellationToken); - protected override RegisterFixData TryGetLanguageSpecificFixInfo( + protected override RegisterFixData? TryGetLanguageSpecificFixInfo( SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken) { if (node is ConstructorInitializerSyntax constructorInitializer) { - var constructorDeclaration = constructorInitializer.Parent; + var constructorDeclaration = constructorInitializer.GetRequiredParent(); if (semanticModel.GetDeclaredSymbol(constructorDeclaration, cancellationToken) is IMethodSymbol constructorSymbol) { var type = constructorSymbol.ContainingType; From 8b0a94d41e7d5e7237cb74534b4352f4f94d5431 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:12:49 -0700 Subject: [PATCH 88/98] Add nrt support --- .../GenerateConstructor/GenerateConstructorDiagnosticIds.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/GenerateConstructor/GenerateConstructorDiagnosticIds.cs b/src/Analyzers/CSharp/CodeFixes/GenerateConstructor/GenerateConstructorDiagnosticIds.cs index b821a7fcfd42c..f83c0483fbbae 100644 --- a/src/Analyzers/CSharp/CodeFixes/GenerateConstructor/GenerateConstructorDiagnosticIds.cs +++ b/src/Analyzers/CSharp/CodeFixes/GenerateConstructor/GenerateConstructorDiagnosticIds.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Immutable; namespace Microsoft.CodeAnalysis.CSharp.GenerateConstructor; From 4f6ef0cc6e33ba71bc03e37cb9e0108d6658ceaf Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:13:43 -0700 Subject: [PATCH 89/98] Add nrt support --- .../CSharpRemoveUnusedValuesCodeFixProvider.cs | 10 ++++------ .../AbstractRemoveUnusedValuesCodeFixProvider.cs | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs index 0dc48ef3c9686..434d14f295da9 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnusedParametersAndValues/CSharpRemoveUnusedValuesCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Generic; using System.Composition; using System.Diagnostics; @@ -41,10 +39,10 @@ protected override BlockSyntax WrapWithBlockIfNecessary(IEnumerable node.Identifier; - protected override LocalDeclarationStatementSyntax GetCandidateLocalDeclarationForRemoval(VariableDeclaratorSyntax declarator) + protected override LocalDeclarationStatementSyntax? GetCandidateLocalDeclarationForRemoval(VariableDeclaratorSyntax declarator) => declarator.Parent?.Parent as LocalDeclarationStatementSyntax; - protected override SyntaxNode TryUpdateNameForFlaggedNode(SyntaxNode node, SyntaxToken newName) + protected override SyntaxNode? TryUpdateNameForFlaggedNode(SyntaxNode node, SyntaxToken newName) { switch (node.Kind()) { @@ -91,7 +89,7 @@ protected override SyntaxNode TryUpdateNameForFlaggedNode(SyntaxNode node, Synta } } - protected override SyntaxNode TryUpdateParentOfUpdatedNode(SyntaxNode parent, SyntaxNode newNameNode, SyntaxEditor editor, ISyntaxFacts syntaxFacts, SemanticModel semanticModel) + protected override SyntaxNode? TryUpdateParentOfUpdatedNode(SyntaxNode parent, SyntaxNode newNameNode, SyntaxEditor editor, ISyntaxFacts syntaxFacts, SemanticModel semanticModel) { if (newNameNode.IsKind(SyntaxKind.DiscardDesignation)) { @@ -179,7 +177,7 @@ protected override void InsertAtStartOfSwitchCaseBlockForDeclarationInCaseLabelO { // Switch section without any statements is an error case. // Insert before containing switch statement. - editor.InsertBefore(switchCaseBlock.Parent, declarationStatement); + editor.InsertBefore(switchCaseBlock.GetRequiredParent(), declarationStatement); } } diff --git a/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs index fe31e1baf04c7..1b23c3f0ee10b 100644 --- a/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs @@ -73,7 +73,7 @@ public sealed override ImmutableArray FixableDiagnosticIds /// /// Flagged node containing the identifier token to be replaced. /// New identifier token - protected abstract SyntaxNode TryUpdateNameForFlaggedNode(SyntaxNode node, SyntaxToken newName); + protected abstract SyntaxNode? TryUpdateNameForFlaggedNode(SyntaxNode node, SyntaxToken newName); /// /// Gets the identifier token for the iteration variable of the given foreach statement node. @@ -742,7 +742,7 @@ bool ShouldRemoveStatement(TLocalDeclarationStatementSyntax localDeclarationStat } } - protected abstract TLocalDeclarationStatementSyntax GetCandidateLocalDeclarationForRemoval(TVariableDeclaratorSyntax declarator); + protected abstract TLocalDeclarationStatementSyntax? GetCandidateLocalDeclarationForRemoval(TVariableDeclaratorSyntax declarator); private async Task PostProcessDocumentAsync( Document document, From d58662d65f1e9c76f0936c548186007017ddeda7 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:14:05 -0700 Subject: [PATCH 90/98] Add nrt support --- .../MultiLineConditionalExpressionFormattingRule.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.cs b/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.cs index 7b9bdb36fc3ee..ddc9d75b782ab 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseConditionalExpression/MultiLineConditionalExpressionFormattingRule.cs @@ -2,11 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Generic; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Formatting.Rules; +using Microsoft.CodeAnalysis.Shared.Extensions; using static Microsoft.CodeAnalysis.UseConditionalExpression.UseConditionalExpressionCodeFixHelpers; namespace Microsoft.CodeAnalysis.CSharp.UseConditionalExpression; @@ -32,9 +31,9 @@ private MultiLineConditionalExpressionFormattingRule() } private static bool IsQuestionOrColonOfNewConditional(SyntaxToken token) - => token.Kind() is SyntaxKind.QuestionToken or SyntaxKind.ColonToken && token.Parent.HasAnnotation(SpecializedFormattingAnnotation); + => token.Kind() is SyntaxKind.QuestionToken or SyntaxKind.ColonToken && token.GetRequiredParent().HasAnnotation(SpecializedFormattingAnnotation); - public override AdjustNewLinesOperation GetAdjustNewLinesOperation( + public override AdjustNewLinesOperation? GetAdjustNewLinesOperation( in SyntaxToken previousToken, in SyntaxToken currentToken, in NextGetAdjustNewLinesOperation nextOperation) { if (IsQuestionOrColonOfNewConditional(currentToken)) From dbb782c0713d54ca6c6fcd14b7ecdab4f1c025d9 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:14:23 -0700 Subject: [PATCH 91/98] Add nrt support --- .../CSharpUseDeconstructionCodeFixProvider.cs | 2 -- .../UseExpressionBody/UseExpressionBodyCodeFixProvider.cs | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs index 2ffc570085015..5aa5bb3662f7e 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Immutable; using System.Composition; diff --git a/src/Analyzers/CSharp/CodeFixes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs index 75c711fece736..e786ec9531600 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -56,7 +54,7 @@ protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) { - var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); + var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); var accessorLists = new HashSet(); foreach (var diagnostic in diagnostics) From de0632d51023282be8a64bb024efd216288132de Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:14:29 -0700 Subject: [PATCH 92/98] Add nrt support --- .../UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs index a510ac49a46af..9e7e7aefb59f8 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; From 343ac0f38d9c38da3a31d99ee1cbd230c4d1dc38 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:14:35 -0700 Subject: [PATCH 93/98] Add nrt support --- .../CSharpUseIndexOperatorCodeFixProvider.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs index e96ac33c3be9e..01b8a9424b779 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; From fd1da7ab48c31794c9284f6f71572b70dfe9234d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:14:41 -0700 Subject: [PATCH 94/98] Add nrt support --- .../CSharp/CodeFixes/UseIndexOrRangeOperator/Helpers.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/Helpers.cs b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/Helpers.cs index 62b9558db992e..4bfd30a9f3ebf 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/Helpers.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/Helpers.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; From eb8362c4218fcb577ea8f139013d19fd1563cdf6 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:14:47 -0700 Subject: [PATCH 95/98] Add nrt support --- .../CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs index 2b634f752f0a8..a099c36cde8f4 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; From 81ecd91493f20bf626a63c55b895aff5176c5a9b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:14:54 -0700 Subject: [PATCH 96/98] Add nrt support --- .../CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs index d342aed3dda21..8e545e1dc054c 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForReferenceEqualsCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Composition; using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; From dc48454235b51b7f5f0d95ec4f442a2fc10ecbed Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:15:19 -0700 Subject: [PATCH 97/98] Add nrt support --- .../UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs | 2 -- .../UseSimpleUsingStatementCodeFixProvider.cs | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs index 931722e8eb838..379c220cda49b 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Generic; using System.Collections.Immutable; diff --git a/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs index f2feec8761fe0..d023cc81f1a42 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Generic; using System.Collections.Immutable; From 0a6f8a5df1d160fcc88ebe7c0b529f7a6158c35f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 Jul 2024 12:21:10 -0700 Subject: [PATCH 98/98] Add nrt support --- .../UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs | 2 ++ .../UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs | 2 ++ .../UseSimpleUsingStatementCodeFixProvider.cs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs index 5aa5bb3662f7e..2ffc570085015 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable disable + using System; using System.Collections.Immutable; using System.Composition; diff --git a/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs index 379c220cda49b..931722e8eb838 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable disable + using System; using System.Collections.Generic; using System.Collections.Immutable; diff --git a/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs index d023cc81f1a42..f2feec8761fe0 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable disable + using System; using System.Collections.Generic; using System.Collections.Immutable;