Common Practices and Code Improvements
- Access to a static member of a type via a derived type
Access to a static member of a type via a derived type.
- Actual number of bytes read by 'Stream.Read()' is ignored
Actual number of bytes read by 'Stream.Read()' is ignored.
- Add explicit 'return' or 'continue' before local functions
Add explicit 'return' or 'continue' before local functions.
- Annotation duplicate in hierarchy
Annotation duplicate in hierarchy.
- Auto-property can be made get-only (non-private accessibility)
Auto-property can be made get-only (non-private accessibility).
- Auto-property can be made get-only (private accessibility)
Auto-property can be made get-only (private accessibility).
- Base member has 'params' parameter, but the overrider does not have it
Base member has 'params' parameter, but the overrider does not have it.
- Can simplify 'Contains' before 'Add'
Can simplify 'Contains' before 'Add'.
- Cast expression can be replaced with explicit type arguments
Cast expression can be replaced with explicit type arguments.
- Cast expression can be replaced with explicit variable type
Cast expression can be replaced with explicit variable type.
- Cast expression can be replaced with lambda return type
Cast expression can be replaced with lambda return type.
- Cast expression can be replaced with simplified type arguments
Cast expression can be replaced with simplified type arguments.
- Change lock field type to 'System.Threading.Lock'
Change lock field type to 'System.Threading.Lock'.
- Check for reference equality instead
Check for reference equality instead.
- Class can be made sealed (non-inheritable) (non-private accessibility)
Class can be made sealed (non-inheritable) (non-private accessibility).
- Class can be made sealed (non-inheritable) (private accessibility)
Class can be made sealed (non-inheritable) (private accessibility).
- Confusing body-like statement
Confusing body-like statement.
- Container nullability attribute usage with declaration of non-container type
Container nullability attribute usage with declaration of non-container type.
- Convert 'if do while' into 'while'
Convert 'if do while' into 'while'.
- Convert 'if' into '||'
Convert 'if' into '||'.
- Convert local variable or field into constant (non-private accessibility)
Convert local variable or field into constant (non-private accessibility).
- Convert local variable or field into constant (private accessibility)
Convert local variable or field into constant (private accessibility).
- Declaration nullability inferred (parameter is inferred to be not null)
Declaration nullability inferred (parameter is inferred to be not null).
- Declaration nullability inferred (parameter is inferred to be nullable)
Declaration nullability inferred (parameter is inferred to be nullable).
- Declaration nullability inferred (type member is inferred to be not null)
Declaration nullability inferred (type member is inferred to be not null).
- Declaration nullability inferred (type member is inferred to be nullable)
Declaration nullability inferred (type member is inferred to be nullable).
- Dictionary item removal can be simplified with single 'Remove'
Dictionary item removal can be simplified with single 'Remove'.
- Dictionary lookup can be simplified with 'GetValueOrDefault'
Dictionary lookup can be simplified with 'GetValueOrDefault'.
- Dictionary lookup can be simplified with 'TryAdd'
Dictionary lookup can be simplified with 'TryAdd'.
- Dictionary lookup can be simplified with 'TryGetValue'
Dictionary lookup can be simplified with 'TryGetValue'.
- Empty statement is redundant
Empty statement is redundant.
- Extract common property pattern
Extract common property pattern.
- Field can be made readonly (non-private accessibility)
Field can be made readonly (non-private accessibility).
- Field can be made readonly (private accessibility)
Field can be made readonly (private accessibility).
- Get-only auto-property is never assigned
Get-only auto-property is never assigned.
- Invert condition
Invert condition.
- Iteration variable can be declared with a more specific type
Iteration variable can be declared with a more specific type.
- Join local variable declaration and assignment
Join local variable declaration and assignment.
- Local function can be made static
Local function can be made static.
- Local variable has too wide declaration scope
Local variable has too wide declaration scope.
- Make constructor in abstract class protected
Make constructor in abstract class protected.
- Member can be made private (non-private accessibility)
Member can be made private (non-private accessibility).
- Member can be made private (private accessibility)
Member can be made private (private accessibility).
- Member can be made protected (non-private accessibility)
Member can be made protected (non-private accessibility).
- Member can be made protected (private accessibility)
Member can be made protected (private accessibility).
- Member can be made static (shared) (non-private accessibility)
Member can be made static (shared) (non-private accessibility).
- Member can be made static (shared) (private accessibility)
Member can be made static (shared) (private accessibility).
- Member or type can be made internal (friend)
Member or type can be made internal (friend).
- Method has async overload
Method has async overload.
- Method has async overload with cancellation support
Method has async overload with cancellation support.
- Method supports cancellation
Method supports cancellation.
- Missing XML comment for private or internal type or member
Missing XML comment for private or internal type or member.
- Multiple nullable attributes usage
Multiple nullable attributes usage.
- Nested string interpolation can be inlined
Nested string interpolation can be inlined.
- Nullability attribute usage with declaration of void or value type
Nullability attribute usage with declaration of void or value type.
- Nullability attribute used with declaration that cannot be directly referenced from other code
Nullability attribute used with declaration that cannot be directly referenced from other code.
- Parameter can be declared with the base type
Parameter can be declared with the base type.
- Parameter of the constructor can be declared with the base type
Parameter of the constructor can be declared with the base type.
- Parameter type can be IEnumerable<T> (non-private accessibility)
Parameter type can be IEnumerable<T> (non-private accessibility).
- Parameter type can be IEnumerable<T> (private accessibility)
Parameter type can be IEnumerable<T> (private accessibility).
- Prefer using concrete value over 'default' or 'new()'
Prefer using concrete value over 'default' or 'new()'.
- Property can be made init-only (non-private accessibility)
Property can be made init-only (non-private accessibility).
- Property can be made init-only (private accessibility)
Property can be made init-only (private accessibility).
- Put local function after 'return' or 'continue'
Put local function after 'return' or 'continue'.
- Redundant 'is'
Redundant 'is'.
- Remove constructor invocation
Remove constructor invocation.
- Remove redundant statement
Remove redundant statement.
- Remove ToList()
Remove ToList().
- Replace 'async' code with 'Task'-return
Replace 'async' code with 'Task'-return.
- Replace with FirstOrDefault($args$)
Replace with FirstOrDefault($args$).
- Replace with LastOrDefault($args$)
Replace with LastOrDefault($args$).
- Replace with OfType<T>()
Replace with OfType<T>().
- Replace with OfType<T>().Any()
Replace with OfType<T>().Any().
- Replace with OfType<T>().Any() (replace with OfType<T>().Any(..))
Replace with OfType<T>().Any() (replace with OfType<T>().Any(..)).
- Replace with OfType<T>().Count()
Replace with OfType<T>().Count().
- Replace with OfType<T>().Count() (replace with OfType<T>().Count(..))
Replace with OfType<T>().Count() (replace with OfType<T>().Count(..)).
- Replace with OfType<T>().First()
Replace with OfType<T>().First().
- Replace with OfType<T>().First() (replace with OfType<T>().First(..))
Replace with OfType<T>().First() (replace with OfType<T>().First(..)).
- Replace with OfType<T>().FirstOrDefault()
Replace with OfType<T>().FirstOrDefault().
- Replace with OfType<T>().FirstOrDefault() (replace with OfType<T>().FirstOrDefault(..))
Replace with OfType<T>().FirstOrDefault() (replace with OfType<T>().FirstOrDefault(..)).
- Replace with OfType<T>().Last()
Replace with OfType<T>().Last().
- Replace with OfType<T>().Last() (replace with OfType<T>().Last(..))
Replace with OfType<T>().Last() (replace with OfType<T>().Last(..)).
- Replace with OfType<T>().LastOrDefault()
Replace with OfType<T>().LastOrDefault().
- Replace with OfType<T>().LastOrDefault() (replace with OfType<T>().LastOrDefault(..))
Replace with OfType<T>().LastOrDefault() (replace with OfType<T>().LastOrDefault(..)).
- Replace with OfType<T>().LongCount()
Replace with OfType<T>().LongCount().
- Replace with OfType<T>().Single()
Replace with OfType<T>().Single().
- Replace with OfType<T>().Single() (replace with OfType<T>().Single(..))
Replace with OfType<T>().Single() (replace with OfType<T>().Single(..)).
- Replace with OfType<T>().SingleOrDefault()
Replace with OfType<T>().SingleOrDefault().
- Replace with OfType<T>().SingleOrDefault() (replace with OfType<T>().SingleOrDefault(..))
Replace with OfType<T>().SingleOrDefault() (replace with OfType<T>().SingleOrDefault(..)).
- Replace with OfType<T>().Where() (replace with OfType<T>().Where(..))
Replace with OfType<T>().Where() (replace with OfType<T>().Where(..)).
- Replace with simple assignment
Replace with simple assignment.
- Replace with single assignment
Replace with single assignment.
- Replace with single call to Any(..)
Replace with single call to Any(..).
- Replace with single call to Count(..)
Replace with single call to Count(..).
- Replace with single call to First(..)
Replace with single call to First(..).
- Replace with single call to FirstOrDefault(..)
Replace with single call to FirstOrDefault(..).
- Replace with single call to Last(..)
Replace with single call to Last(..).
- Replace with single call to LastOrDefault(..)
Replace with single call to LastOrDefault(..).
- Replace with single call to Single(..)
Replace with single call to Single(..).
- Replace with single call to SingleOrDefault(..)
Replace with single call to SingleOrDefault(..).
- Replace with SingleOrDefault($args$)
Replace with SingleOrDefault($args$).
- Return type can be IEnumerable<T> (non-private accessibility)
Return type can be IEnumerable<T> (non-private accessibility).
- Return type can be IEnumerable<T> (private accessibility)
Return type can be IEnumerable<T> (private accessibility).
- Simplify 'IsInstanceOfType()' invocation
Simplify 'IsInstanceOfType()' invocation.
- Simplify conditional ternary expression
Simplify conditional ternary expression.
- Simplify LINQ expression (use 'All')
Simplify LINQ expression (use 'All').
- Simplify LINQ expression (use 'Any')
Simplify LINQ expression (use 'Any').
- Simplify negated pattern
Simplify negated pattern.
- Simplify negated relational pattern
Simplify negated relational pattern.
- Simplify negative equality expression
Simplify negative equality expression.
- Specify string comparison explicitly
Specify string comparison explicitly.
- Specify string culture explicitly
Specify string culture explicitly.
- String literal can be inlined
String literal can be inlined.
- String.Compare is culture-specific (string.Compare(string, int, string, int) is culture-specific)
String.Compare is culture-specific (string.Compare(string, int, string, int) is culture-specific).
- String.Compare is culture-specific (string.Compare(string, int, string, int, bool) is culture-specific)
String.Compare is culture-specific (string.Compare(string, int, string, int, bool) is culture-specific).
- String.Compare is culture-specific (string.Compare(string, string) is culture-specific)
String.Compare is culture-specific (string.Compare(string, string) is culture-specific).
- String.Compare is culture-specific (string.Compare(string, string, bool) is culture-specific)
String.Compare is culture-specific (string.Compare(string, string, bool) is culture-specific).
- String.CompareTo is culture-specific
String.CompareTo is culture-specific.
- String.EndsWith is culture-specific (string.EndsWith(string) is culture-specific)
String.EndsWith is culture-specific (string.EndsWith(string) is culture-specific).
- String.IndexOf is culture-specific (string.IndexOf(string) is culture-specific)
String.IndexOf is culture-specific (string.IndexOf(string) is culture-specific).
- String.IndexOf is culture-specific (string.IndexOf(string, int) is culture-specific)
String.IndexOf is culture-specific (string.IndexOf(string, int) is culture-specific).
- String.LastIndexOf is culture-specific (string.LastIndexOf(string) is culture-specific)
String.LastIndexOf is culture-specific (string.LastIndexOf(string) is culture-specific).
- String.LastIndexOf is culture-specific (string.LastIndexOf(string, int) is culture-specific)
String.LastIndexOf is culture-specific (string.LastIndexOf(string, int) is culture-specific).
- String.StartsWith is culture-specific (string.StartsWith(string) is culture-specific)
String.StartsWith is culture-specific (string.StartsWith(string) is culture-specific).
- Struct can be made readonly
Struct can be made readonly.
- Struct lacks 'IEquatable' implementation (non-private accessibility)
Struct lacks 'IEquatable' implementation (non-private accessibility).
- Struct lacks 'IEquatable' implementation (private accessibility)
Struct lacks 'IEquatable' implementation (private accessibility).
- Struct member can be made readonly
Struct member can be made readonly.
- Struct with default equality members is used for comparison (non-private accessibility)
Struct with default equality members is used for comparison (non-private accessibility).
- Struct with default equality members is used for comparison (private accessibility)
Struct with default equality members is used for comparison (private accessibility).
- try-catch and try-finally statements can be merged
try-catch and try-finally statements can be merged.
- Type can be made file-local
Type can be made file-local.
- Type parameter could be declared as covariant or contravariant
Type parameter could be declared as covariant or contravariant.
- Type with suspicious equality is used in a record (non-private accessibility)
Type with suspicious equality is used in a record (non-private accessibility).
- Type with suspicious equality is used in a record (private accessibility)
Type with suspicious equality is used in a record (private accessibility).
- Usage of default struct equality
Usage of default struct equality.
- Use 'ArgumentNullException.ThrowIfNull'
Use 'ArgumentNullException.ThrowIfNull'.
- Use 'Array.Empty<T>()'
Use 'Array.Empty<T>()'.
- Use 'EventArgs.Empty'
Use 'EventArgs.Empty'.
- Use 'is' operator
Use 'is' operator.
- Use 'String.IsNullOrEmpty'
Use 'String.IsNullOrEmpty'.
- Use 'Type.EmptyTypes'
Use 'Type.EmptyTypes'.
- Use array creation expression
Use array creation expression.
- Use cancellation token
Use cancellation token.
- Use compiler-supported nullable attributes
Use compiler-supported nullable attributes.
- Use indexed property
Use indexed property.
- Use method Any()
Use method Any().