diff --git a/Src/FluentAssertions/CallerIdentification/MultiLineCommentParsingStrategy.cs b/Src/FluentAssertions/CallerIdentification/MultiLineCommentParsingStrategy.cs index b3fb431e08..6e22a04799 100644 --- a/Src/FluentAssertions/CallerIdentification/MultiLineCommentParsingStrategy.cs +++ b/Src/FluentAssertions/CallerIdentification/MultiLineCommentParsingStrategy.cs @@ -11,7 +11,7 @@ public ParsingState Parse(char symbol, StringBuilder statement) { if (isCommentContext) { - var isEndOfMultilineComment = symbol == '/' && commentContextPreviousChar == '*'; + var isEndOfMultilineComment = symbol is '/' && commentContextPreviousChar is '*'; if (isEndOfMultilineComment) { isCommentContext = false; @@ -26,9 +26,9 @@ public ParsingState Parse(char symbol, StringBuilder statement) } var isStartOfMultilineComment = - symbol == '*' + symbol is '*' && statement.Length > 0 - && statement[statement.Length - 1] == '/'; + && statement[^1] is '/'; if (isStartOfMultilineComment) { statement.Remove(statement.Length - 1, 1); diff --git a/Src/FluentAssertions/CallerIdentification/QuotesParsingStrategy.cs b/Src/FluentAssertions/CallerIdentification/QuotesParsingStrategy.cs index cd33b0fd69..85991ead02 100644 --- a/Src/FluentAssertions/CallerIdentification/QuotesParsingStrategy.cs +++ b/Src/FluentAssertions/CallerIdentification/QuotesParsingStrategy.cs @@ -1,5 +1,4 @@ -using System.Linq; -using System.Text; +using System.Text; namespace FluentAssertions.CallerIdentification; @@ -11,7 +10,7 @@ internal class QuotesParsingStrategy : IParsingStrategy public ParsingState Parse(char symbol, StringBuilder statement) { - if (symbol == '"') + if (symbol is '"') { if (isQuoteContext) { @@ -54,17 +53,7 @@ public void NotifyEndOfLineReached() private bool IsVerbatim(StringBuilder statement) { - return - statement.Length >= 1 - && - new[] - { - "$@", - "@$", - } - .Any(verbatimStringOpener => - previousChar == verbatimStringOpener[1] - && statement[statement.Length - 1] == verbatimStringOpener[1] - && statement[statement.Length - 2] == verbatimStringOpener[0]); + return (previousChar is '@' && statement.Length >= 2 && statement[^2] is '$' && statement[^1] is '@') + || (previousChar is '$' && statement.Length >= 2 && statement[^2] is '@' && statement[^1] is '$'); } } diff --git a/Src/FluentAssertions/CallerIdentification/SemicolonParsingStrategy.cs b/Src/FluentAssertions/CallerIdentification/SemicolonParsingStrategy.cs index 9448c78ae0..17a6601cc0 100644 --- a/Src/FluentAssertions/CallerIdentification/SemicolonParsingStrategy.cs +++ b/Src/FluentAssertions/CallerIdentification/SemicolonParsingStrategy.cs @@ -6,7 +6,7 @@ internal class SemicolonParsingStrategy : IParsingStrategy { public ParsingState Parse(char symbol, StringBuilder statement) { - if (symbol == ';') + if (symbol is ';') { statement.Clear(); return ParsingState.Done; diff --git a/Src/FluentAssertions/CallerIdentification/SingleLineCommentParsingStrategy.cs b/Src/FluentAssertions/CallerIdentification/SingleLineCommentParsingStrategy.cs index bbb7b322c8..434e1c3b0e 100644 --- a/Src/FluentAssertions/CallerIdentification/SingleLineCommentParsingStrategy.cs +++ b/Src/FluentAssertions/CallerIdentification/SingleLineCommentParsingStrategy.cs @@ -13,7 +13,7 @@ public ParsingState Parse(char symbol, StringBuilder statement) return ParsingState.GoToNextSymbol; } - var doesSymbolStartComment = symbol == '/' && statement.Length > 0 && statement[statement.Length - 1] == '/'; + var doesSymbolStartComment = symbol is '/' && statement.Length > 0 && statement[^1] is '/'; if (!doesSymbolStartComment) { return ParsingState.InProgress; diff --git a/Src/FluentAssertions/CallerIdentifier.cs b/Src/FluentAssertions/CallerIdentifier.cs index 5cb51c85c9..91bceb00bc 100644 --- a/Src/FluentAssertions/CallerIdentifier.cs +++ b/Src/FluentAssertions/CallerIdentifier.cs @@ -71,7 +71,7 @@ public static string DetermineCallerIdentity() return caller; } - private class StackFrameReference : IDisposable + private sealed class StackFrameReference : IDisposable { public int SkipStackFrameCount { get; } @@ -161,7 +161,7 @@ private static bool IsDotNet(StackFrame frame) private static bool IsCompilerServices(StackFrame frame) { - return frame.GetMethod()?.DeclaringType?.Namespace == "System.Runtime.CompilerServices"; + return frame.GetMethod()?.DeclaringType?.Namespace is "System.Runtime.CompilerServices"; } private static string ExtractVariableNameFrom(StackFrame frame) diff --git a/Src/FluentAssertions/Collections/GenericCollectionAssertions.cs b/Src/FluentAssertions/Collections/GenericCollectionAssertions.cs index 1240834a40..63d234c038 100644 --- a/Src/FluentAssertions/Collections/GenericCollectionAssertions.cs +++ b/Src/FluentAssertions/Collections/GenericCollectionAssertions.cs @@ -3246,7 +3246,7 @@ private static string GetExpressionOrderString(Expression @namespace is null; bool IsExactNamespace() => IsNamespacePrefix() && type.Namespace.Length == @namespace.Length; - bool IsParentNamespace() => IsNamespacePrefix() && type.Namespace[@namespace.Length] == '.'; + bool IsParentNamespace() => IsNamespacePrefix() && type.Namespace[@namespace.Length] is '.'; bool IsNamespacePrefix() => type.Namespace?.StartsWith(@namespace, StringComparison.Ordinal) == true; } @@ -520,14 +520,14 @@ public static bool IsSameOrInherits(this Type actualType, Type expectedType) public static MethodInfo GetExplicitConversionOperator(this Type type, Type sourceType, Type targetType) { return type - .GetConversionOperators(sourceType, targetType, name => name == "op_Explicit") + .GetConversionOperators(sourceType, targetType, name => name is "op_Explicit") .SingleOrDefault(); } public static MethodInfo GetImplicitConversionOperator(this Type type, Type sourceType, Type targetType) { return type - .GetConversionOperators(sourceType, targetType, name => name == "op_Implicit") + .GetConversionOperators(sourceType, targetType, name => name is "op_Implicit") .SingleOrDefault(); } diff --git a/Src/FluentAssertions/Equivalency/MultiDimensionalArrayEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/MultiDimensionalArrayEquivalencyStep.cs index 16f7abf311..67068ac0ba 100644 --- a/Src/FluentAssertions/Equivalency/MultiDimensionalArrayEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/MultiDimensionalArrayEquivalencyStep.cs @@ -13,7 +13,7 @@ internal class MultiDimensionalArrayEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, IEquivalencyValidator nestedValidator) { - if (comparands.Expectation is not Array expectationAsArray || expectationAsArray?.Rank == 1) + if (comparands.Expectation is not Array expectationAsArray || expectationAsArray.Rank == 1) { return EquivalencyResult.ContinueWithNext; } diff --git a/Src/FluentAssertions/Equivalency/Ordering/CollectionMemberObjectInfo.cs b/Src/FluentAssertions/Equivalency/Ordering/CollectionMemberObjectInfo.cs index 5f5b9d63c3..61dc3d502f 100644 --- a/Src/FluentAssertions/Equivalency/Ordering/CollectionMemberObjectInfo.cs +++ b/Src/FluentAssertions/Equivalency/Ordering/CollectionMemberObjectInfo.cs @@ -7,11 +7,11 @@ internal class CollectionMemberObjectInfo : IObjectInfo public CollectionMemberObjectInfo(IObjectInfo context) { Path = GetAdjustedPropertyPath(context.Path); - + #pragma warning disable CS0618 Type = context.Type; #pragma warning restore CS0618 - + ParentType = context.ParentType; RuntimeType = context.RuntimeType; CompileTimeType = context.CompileTimeType; @@ -23,7 +23,7 @@ private static string GetAdjustedPropertyPath(string propertyPath) } public Type Type { get; } - + public Type ParentType { get; } public string Path { get; set; } diff --git a/Src/FluentAssertions/Formatting/PredicateLambdaExpressionValueFormatter.cs b/Src/FluentAssertions/Formatting/PredicateLambdaExpressionValueFormatter.cs index d5a2f83862..a05f1088fb 100644 --- a/Src/FluentAssertions/Formatting/PredicateLambdaExpressionValueFormatter.cs +++ b/Src/FluentAssertions/Formatting/PredicateLambdaExpressionValueFormatter.cs @@ -10,7 +10,7 @@ namespace FluentAssertions.Formatting; /// public class PredicateLambdaExpressionValueFormatter : IValueFormatter { - public bool CanHandle(object value) => value is LambdaExpression lambdaExpression; + public bool CanHandle(object value) => value is LambdaExpression; public void Format(object value, FormattedObjectGraph formattedGraph, FormattingContext context, FormatChild formatChild) { @@ -57,7 +57,7 @@ private static IEnumerable ExtractChainOfExpressionsJoinedWithAndOpe /// /// Expression visitor which can detect whether the expression depends on parameters. /// - private class ParameterDetector : ExpressionVisitor + private sealed class ParameterDetector : ExpressionVisitor { public bool HasParameters { get; private set; } @@ -77,7 +77,7 @@ protected override Expression VisitParameter(ParameterExpression node) /// /// Expression visitor which can replace constant sub-expressions with constant values. /// - private class ConstantSubExpressionReductionVisitor : ExpressionVisitor + private sealed class ConstantSubExpressionReductionVisitor : ExpressionVisitor { public override Expression Visit(Expression node) { @@ -114,7 +114,7 @@ private static bool ExpressionIsConstant(Expression expression) /// Expression visitor which can extract sub-expressions from an expression which has the following form: /// (SubExpression1) AND (SubExpression2) ... AND (SubExpressionN) /// - private class AndOperatorChainExtractor : ExpressionVisitor + private sealed class AndOperatorChainExtractor : ExpressionVisitor { public List AndChain { get; } = new List(); diff --git a/Tests/FluentAssertions.Equivalency.Specs/ExtensibilitySpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/ExtensibilitySpecs.cs index f6dfce3a8b..34ce4a3fc5 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/ExtensibilitySpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/ExtensibilitySpecs.cs @@ -140,7 +140,7 @@ public void When_a_matching_rule_is_added_it_should_appear_in_the_exception_mess internal class ForeignKeyMatchingRule : IMemberMatchingRule { - public IMember Match(IMember expectedMember, object subject, INode parent, IEquivalencyAssertionOptions config) + public IMember Match(IMember expectedMember, object subject, INode parent, IEquivalencyAssertionOptions options) { string name = expectedMember.Name; if (name.EndsWith("Id", StringComparison.Ordinal)) @@ -191,7 +191,7 @@ public void When_an_ordering_rule_is_added_it_should_appear_in_the_exception_mes internal class StrictOrderingRule : IOrderingRule { - public OrderStrictness Evaluate(IObjectInfo memberInfo) + public OrderStrictness Evaluate(IObjectInfo objectInfo) { return OrderStrictness.Strict; } @@ -626,7 +626,7 @@ private class AlwaysFailOnDateTimesEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, IEquivalencyValidator nestedValidator) { - if (comparands.Expectation is DateTime time) + if (comparands.Expectation is DateTime) { throw new Exception("Failed"); }