diff --git a/src/ArgumentParsing.CodeFixes/AnnotateTypeWithOptionsTypeAttributeCodeFixProvider.cs b/src/ArgumentParsing.CodeFixes/AnnotateTypeWithOptionsTypeAttributeCodeFixProvider.cs index ca89d55..fedee7d 100644 --- a/src/ArgumentParsing.CodeFixes/AnnotateTypeWithOptionsTypeAttributeCodeFixProvider.cs +++ b/src/ArgumentParsing.CodeFixes/AnnotateTypeWithOptionsTypeAttributeCodeFixProvider.cs @@ -41,9 +41,9 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) var compilation = semanticModel.Compilation; // We can get ParseResult in case the whole type is aliased, so unwrap options type from ParseResult here - if (optionsType?.OriginalDefinition.Equals(compilation.ParseResultOfTType(), SymbolEqualityComparer.Default) == true) + if (SymbolEqualityComparer.Default.Equals(optionsType?.OriginalDefinition, compilation.ParseResultOfTType())) { - optionsType = ((INamedTypeSymbol)optionsType).TypeArguments[0]; + optionsType = ((INamedTypeSymbol)optionsType!).TypeArguments[0]; } if (optionsType?.Locations.First() is not { IsInSource: true } optionsTypeSourceLocation) diff --git a/src/ArgumentParsing.CodeFixes/DeclareSpecialCommandAliasCodeFixProvider.cs b/src/ArgumentParsing.CodeFixes/DeclareSpecialCommandAliasCodeFixProvider.cs index 093d24e..ba2db8c 100644 --- a/src/ArgumentParsing.CodeFixes/DeclareSpecialCommandAliasCodeFixProvider.cs +++ b/src/ArgumentParsing.CodeFixes/DeclareSpecialCommandAliasCodeFixProvider.cs @@ -54,7 +54,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) var aliasesAttributeReference = commandHandler .GetAttributes() - .First(a => a.AttributeClass?.Equals(specialCommandAliasesAttributeType, SymbolEqualityComparer.Default) == true) + .First(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, specialCommandAliasesAttributeType)) .ApplicationSyntaxReference; if (aliasesAttributeReference is null) diff --git a/src/ArgumentParsing.Generators/ArgumentParserGenerator.Extract.cs b/src/ArgumentParsing.Generators/ArgumentParserGenerator.Extract.cs index 0a5c40a..0bc574f 100644 --- a/src/ArgumentParsing.Generators/ArgumentParserGenerator.Extract.cs +++ b/src/ArgumentParsing.Generators/ArgumentParserGenerator.Extract.cs @@ -22,7 +22,7 @@ private static (ArgumentParserInfo? ArgumentParserInfo, OptionsHelpInfo? Options var comp = context.SemanticModel.Compilation; var genArgParserAttrType = comp.GetTypeByMetadataName(GeneratedArgumentParserAttributeName)!; - var genArgParserAttrData = context.Attributes.First(a => a.AttributeClass?.Equals(genArgParserAttrType, SymbolEqualityComparer.Default) == true); + var genArgParserAttrData = context.Attributes.First(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, genArgParserAttrType)); ImmutableArray.Builder? specialCommandHandlerInfosBuilder = null; if (genArgParserAttrData.NamedArguments.FirstOrDefault(static n => n.Key == "SpecialCommandHandlers").Value is { IsNull: false, Values: { IsDefault: false } specialCommandHandlers }) @@ -42,7 +42,7 @@ private static (ArgumentParserInfo? ArgumentParserInfo, OptionsHelpInfo? Options var aliasesAttrData = commandHandlerType .GetAttributes() - .FirstOrDefault(a => a.AttributeClass?.Equals(specialCommandAliasesAttributeType, SymbolEqualityComparer.Default) == true); + .FirstOrDefault(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, specialCommandAliasesAttributeType)); if (aliasesAttrData is null) { @@ -107,7 +107,7 @@ private static (ArgumentParserInfo? ArgumentParserInfo, OptionsHelpInfo? Options if (optionsType is not INamedTypeSymbol { SpecialType: SpecialType.None, TypeKind: TypeKind.Class or TypeKind.Struct } namedOptionsType || !namedOptionsType.Constructors.Any(static c => c.DeclaredAccessibility >= Accessibility.Internal && c.Parameters.IsEmpty) || - !namedOptionsType.GetAttributes().Any(a => a.AttributeClass?.Equals(comp.OptionsTypeAttributeType(), SymbolEqualityComparer.Default) == true)) + !namedOptionsType.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, comp.OptionsTypeAttributeType()))) { return default; } @@ -142,7 +142,7 @@ private static (OptionsInfo? OptionsInfo, OptionsHelpInfo? OptionsHelpInfo) Extr { HelpTextGeneratorInfo? helpTextGeneratorInfo = null; - if (optionsType.GetAttributes().FirstOrDefault(a => a.AttributeClass?.Equals(comp.HelpTextGeneratorAttributeType(), SymbolEqualityComparer.Default) == true) is { } helpTextGeneratorAttribute) + if (optionsType.GetAttributes().FirstOrDefault(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, comp.HelpTextGeneratorAttributeType())) is { } helpTextGeneratorAttribute) { var firstArg = helpTextGeneratorAttribute.ConstructorArguments[0]; var secondArg = helpTextGeneratorAttribute.ConstructorArguments[1]; @@ -547,7 +547,7 @@ private static (EnvironmentInfo EnvironmentInfo, AssemblyVersionInfo AssemblyVer cancellationToken.ThrowIfCancellationRequested(); var generateDefaultVersionSpecialCommandAttributeType = compilation.GetTypeByMetadataName("ArgumentParsing.SpecialCommands.Version.GenerateDefaultVersionSpecialCommandAttribute"); - var forceDefaultVersionCommand = compilation.Assembly.GetAttributes().Any(a => a.AttributeClass?.Equals(generateDefaultVersionSpecialCommandAttributeType, SymbolEqualityComparer.Default) == true); + var forceDefaultVersionCommand = compilation.Assembly.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, generateDefaultVersionSpecialCommandAttributeType)); var environmentInfo = new EnvironmentInfo(canUseOptimalSpanBasedAlgorithm, hasStringStartsWithCharOverload, forceDefaultVersionCommand); diff --git a/src/ArgumentParsing.Generators/Diagnostics/Analyzers/HelpTextGeneratorOnNonOptionsTypeAnalyzer.cs b/src/ArgumentParsing.Generators/Diagnostics/Analyzers/HelpTextGeneratorOnNonOptionsTypeAnalyzer.cs index 53d7593..3717b14 100644 --- a/src/ArgumentParsing.Generators/Diagnostics/Analyzers/HelpTextGeneratorOnNonOptionsTypeAnalyzer.cs +++ b/src/ArgumentParsing.Generators/Diagnostics/Analyzers/HelpTextGeneratorOnNonOptionsTypeAnalyzer.cs @@ -33,13 +33,13 @@ private static void AnalyzeType(SymbolAnalysisContext context, KnownTypes knownT { var type = (INamedTypeSymbol)context.Symbol; var attributes = type.GetAttributes(); - var helpTextGeneratorAttribute = attributes.FirstOrDefault(a => a.AttributeClass?.Equals(knownTypes.HelpTextGeneratorAttributeType, SymbolEqualityComparer.Default) == true); + var helpTextGeneratorAttribute = attributes.FirstOrDefault(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, knownTypes.HelpTextGeneratorAttributeType)); if (helpTextGeneratorAttribute is null) { return; } - if (!attributes.Any(a => a.AttributeClass?.Equals(knownTypes.OptionsTypeAttributeType, SymbolEqualityComparer.Default) == true)) + if (!attributes.Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, knownTypes.OptionsTypeAttributeType))) { context.ReportDiagnostic( Diagnostic.Create( diff --git a/src/ArgumentParsing.Generators/Diagnostics/Analyzers/OptionsTypeAnalyzer.cs b/src/ArgumentParsing.Generators/Diagnostics/Analyzers/OptionsTypeAnalyzer.cs index 6458913..f7f881a 100644 --- a/src/ArgumentParsing.Generators/Diagnostics/Analyzers/OptionsTypeAnalyzer.cs +++ b/src/ArgumentParsing.Generators/Diagnostics/Analyzers/OptionsTypeAnalyzer.cs @@ -81,12 +81,12 @@ private static void AnalyzeOptionsType(SymbolAnalysisContext context, LanguageVe var optionsType = (INamedTypeSymbol)context.Symbol; var attributes = optionsType.GetAttributes(); - if (!attributes.Any(a => a.AttributeClass?.Equals(knownTypes.OptionsTypeAttributeType, SymbolEqualityComparer.Default) == true)) + if (!attributes.Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, knownTypes.OptionsTypeAttributeType))) { return; } - var helpTextGeneratorAttribute = attributes.FirstOrDefault(a => a.AttributeClass?.Equals(knownTypes.HelpTextGeneratorAttributeType, SymbolEqualityComparer.Default) == true); + var helpTextGeneratorAttribute = attributes.FirstOrDefault(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, knownTypes.HelpTextGeneratorAttributeType)); if (helpTextGeneratorAttribute is not null) { var firstArg = helpTextGeneratorAttribute.ConstructorArguments[0]; diff --git a/src/ArgumentParsing.Generators/Diagnostics/Analyzers/ParserRelatedPropertyInNonOptionsTypeAnalyzer.cs b/src/ArgumentParsing.Generators/Diagnostics/Analyzers/ParserRelatedPropertyInNonOptionsTypeAnalyzer.cs index f15156b..5f9d5f1 100644 --- a/src/ArgumentParsing.Generators/Diagnostics/Analyzers/ParserRelatedPropertyInNonOptionsTypeAnalyzer.cs +++ b/src/ArgumentParsing.Generators/Diagnostics/Analyzers/ParserRelatedPropertyInNonOptionsTypeAnalyzer.cs @@ -36,15 +36,15 @@ private static void AnalyzeProperty(SymbolAnalysisContext context, KnownTypes kn var property = (IPropertySymbol)context.Symbol; if (!property.GetAttributes() - .Any(a => a.AttributeClass?.Equals(knownTypes.OptionAttributeType, SymbolEqualityComparer.Default) == true || - a.AttributeClass?.Equals(knownTypes.ParameterAttributeType, SymbolEqualityComparer.Default) == true || - a.AttributeClass?.Equals(knownTypes.RemainingParametersAttributeType, SymbolEqualityComparer.Default) == true)) + .Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, knownTypes.OptionAttributeType) || + SymbolEqualityComparer.Default.Equals(a.AttributeClass, knownTypes.ParameterAttributeType) || + SymbolEqualityComparer.Default.Equals(a.AttributeClass, knownTypes.RemainingParametersAttributeType))) { return; } if (property.ContainingType.GetAttributes() - .Any(a => a.AttributeClass?.Equals(knownTypes.OptionsTypeAttributeType, SymbolEqualityComparer.Default) == true)) + .Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, knownTypes.OptionsTypeAttributeType))) { return; } diff --git a/src/ArgumentParsing.Generators/Diagnostics/Analyzers/ParserSignatureAnalyzer.cs b/src/ArgumentParsing.Generators/Diagnostics/Analyzers/ParserSignatureAnalyzer.cs index c6394d6..c4c681e 100644 --- a/src/ArgumentParsing.Generators/Diagnostics/Analyzers/ParserSignatureAnalyzer.cs +++ b/src/ArgumentParsing.Generators/Diagnostics/Analyzers/ParserSignatureAnalyzer.cs @@ -50,7 +50,7 @@ private static void AnalyzeParserSignature(SymbolAnalysisContext context, KnownT var method = (IMethodSymbol)context.Symbol; if (method.GetAttributes() - .FirstOrDefault(a => a.AttributeClass?.Equals(knownTypes.GeneratedArgumentParserAttributeType, SymbolEqualityComparer.Default) == true) is not { } generatedArgParserAttrData) + .FirstOrDefault(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, knownTypes.GeneratedArgumentParserAttributeType)) is not { } generatedArgParserAttrData) { return; } diff --git a/src/ArgumentParsing.Generators/Diagnostics/Analyzers/SpecialCommandHandlerAnalyzer.cs b/src/ArgumentParsing.Generators/Diagnostics/Analyzers/SpecialCommandHandlerAnalyzer.cs index 6f88aa9..a96fd7f 100644 --- a/src/ArgumentParsing.Generators/Diagnostics/Analyzers/SpecialCommandHandlerAnalyzer.cs +++ b/src/ArgumentParsing.Generators/Diagnostics/Analyzers/SpecialCommandHandlerAnalyzer.cs @@ -56,7 +56,7 @@ private static void AnalyzeSpecialCommandHandler(SymbolAnalysisContext context, diagnosticLocation)); } - var aliasesAttribute = type.GetAttributes().FirstOrDefault(a => a.AttributeClass?.Equals(knownTypes.SpecialCommandAliasesAttributeType, SymbolEqualityComparer.Default) == true); + var aliasesAttribute = type.GetAttributes().FirstOrDefault(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, knownTypes.SpecialCommandAliasesAttributeType)); var constructorArg = aliasesAttribute?.ConstructorArguments[0]; if (aliasesAttribute is null || diff --git a/src/ArgumentParsing.Generators/Diagnostics/Suppressors/ParserRelatedPropertyMarkedWithRequiredAttributeSuppressor.cs b/src/ArgumentParsing.Generators/Diagnostics/Suppressors/ParserRelatedPropertyMarkedWithRequiredAttributeSuppressor.cs index b95db0c..5c9db87 100644 --- a/src/ArgumentParsing.Generators/Diagnostics/Suppressors/ParserRelatedPropertyMarkedWithRequiredAttributeSuppressor.cs +++ b/src/ArgumentParsing.Generators/Diagnostics/Suppressors/ParserRelatedPropertyMarkedWithRequiredAttributeSuppressor.cs @@ -33,14 +33,14 @@ public override void ReportSuppressions(SuppressionAnalysisContext context) var compilation = semanticModel.Compilation; - if (!propertySymbol.ContainingType.GetAttributes().Any(a => a.AttributeClass?.Equals(compilation.OptionsTypeAttributeType(), SymbolEqualityComparer.Default) == true)) + if (!propertySymbol.ContainingType.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, compilation.OptionsTypeAttributeType()))) { continue; } - if (propertySymbol.GetAttributes().Any(a => a.AttributeClass?.Equals(compilation.OptionAttributeType(), SymbolEqualityComparer.Default) == true || - a.AttributeClass?.Equals(compilation.ParameterAttributeType(), SymbolEqualityComparer.Default) == true || - a.AttributeClass?.Equals(compilation.RemainingParametersAttributeType(), SymbolEqualityComparer.Default) == true)) + if (propertySymbol.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, compilation.OptionAttributeType()) || + SymbolEqualityComparer.Default.Equals(a.AttributeClass, compilation.ParameterAttributeType()) || + SymbolEqualityComparer.Default.Equals(a.AttributeClass, compilation.RemainingParametersAttributeType()))) { context.ReportSuppression(Suppression.Create(SuppressionDescriptors.ParserRelatedPropertyMarkedWithRequiredAttributeInOptionsType, diagnostic)); } diff --git a/src/ArgumentParsing.Generators/Diagnostics/Suppressors/RemainingParametersSuppressor.cs b/src/ArgumentParsing.Generators/Diagnostics/Suppressors/RemainingParametersSuppressor.cs index 13e3e30..b72913b 100644 --- a/src/ArgumentParsing.Generators/Diagnostics/Suppressors/RemainingParametersSuppressor.cs +++ b/src/ArgumentParsing.Generators/Diagnostics/Suppressors/RemainingParametersSuppressor.cs @@ -33,12 +33,12 @@ public override void ReportSuppressions(SuppressionAnalysisContext context) var compilation = semanticModel.Compilation; - if (!propertySymbol.ContainingType.GetAttributes().Any(a => a.AttributeClass?.Equals(compilation.OptionsTypeAttributeType(), SymbolEqualityComparer.Default) == true)) + if (!propertySymbol.ContainingType.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, compilation.OptionsTypeAttributeType()))) { continue; } - if (!propertySymbol.GetAttributes().Any(a => a.AttributeClass?.Equals(compilation.RemainingParametersAttributeType(), SymbolEqualityComparer.Default) == true)) + if (!propertySymbol.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, compilation.RemainingParametersAttributeType()))) { continue; } diff --git a/src/ArgumentParsing.Generators/Diagnostics/Suppressors/SequenceTypedOptionSuppressor.cs b/src/ArgumentParsing.Generators/Diagnostics/Suppressors/SequenceTypedOptionSuppressor.cs index 9900f17..d36ca42 100644 --- a/src/ArgumentParsing.Generators/Diagnostics/Suppressors/SequenceTypedOptionSuppressor.cs +++ b/src/ArgumentParsing.Generators/Diagnostics/Suppressors/SequenceTypedOptionSuppressor.cs @@ -33,12 +33,12 @@ public override void ReportSuppressions(SuppressionAnalysisContext context) var compilation = semanticModel.Compilation; - if (!propertySymbol.ContainingType.GetAttributes().Any(a => a.AttributeClass?.Equals(compilation.OptionsTypeAttributeType(), SymbolEqualityComparer.Default) == true)) + if (!propertySymbol.ContainingType.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, compilation.OptionsTypeAttributeType()))) { continue; } - if (!propertySymbol.GetAttributes().Any(a => a.AttributeClass?.Equals(compilation.OptionAttributeType(), SymbolEqualityComparer.Default) == true)) + if (!propertySymbol.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, compilation.OptionAttributeType()))) { continue; }