Style
Composite Recipes
Recipes that include further recipes, often including the individual recipes below.
Recipes
- Abstract type should not have public constructors
- Add parentheses for clarity
- Add parentheses to conditional expression condition
- Add static modifier to all members of static class
- Add trailing comma
- Add trailing comma to last enum member
- ArgumentException should specify argument name
- Avoid chain of assignments
- Avoid nested ternary operator
- Call extension method as instance method
- Composite enum value contains undefined flag
- Convert comment to documentation comment
- Declare each attribute separately
- Declare each type in separate file
- Declare each type in separate file
- Declare enum member with zero value
- Declare enum value as combination of names
- Declare using directive on top level
- Default label should be last
- Do not raise ApplicationException
- Do not raise reserved exception types
- Do not throw NotImplementedException
- Do not throw from finally block
- Do not use ThreadStatic on instance fields
- Do not use anonymous delegates to unsubscribe from events
- Do not use dangerous threading methods
- Do not write custom certificate validation
- Duplicate word in a comment
- Embed caught exception as inner exception
- Enum should declare explicit values
- Find 'is' pattern with string literal
- Find == comparison that should use Equals()
- Find CompareTo without IComparable
- Find DateTime.Now/UtcNow usage
- Find Dictionary/HashSet without StringComparer
- Find ElementAt() that could use indexer
- Find EqualityComparer<string>.Default
- Find Equals without [NotNullWhen(true)]
- Find FormattableString usage
- Find GetType() on Type instance
- Find IAsyncEnumerable method without Async suffix
- Find IComparable without comparison operators
- Find IComparable<T> without IEquatable<T>
- Find IEquatable<T> without Equals(object) override
- Find ILogger<T> type parameter mismatch
- Find Interlocked.CompareExchange lazy init pattern
- Find Parse/ToString without IFormatProvider
- Find Parse/TryParse without IFormatProvider
- Find Process.Start with string argument
- Find ProcessStartInfo without UseShellExecute
- Find Regex without ExplicitCapture option
- Find Stream.Read() return value ignored
- Find Thread.Sleep usage
- Find ThrowIfNull with value type argument
- Find ToString on object-typed parameter
- Find ToString override without DebuggerDisplay
- Find [DefaultParameterValue] without [Optional]
- Find [DefaultValue] on parameter
- Find argument validation in iterator method
- Find async call missing CancellationToken
- Find async void delegate
- Find async void method
- Find await foreach without CancellationToken
- Find binary expression with identical sides
- Find boolean literal argument without name
- Find boolean literal arguments without parameter name
- Find class with Equals(T) but no IEquatable<T>
- Find collection emptiness check
- Find comparison with NaN
- Find concrete collection in public API
- Find custom time abstraction
- Find double await pattern
- Find equality operator on Span<T>
- Find event raised with null EventArgs
- Find explicit zero initialization in enum
- Find if/else with identical branches
- Find implicit DateTime to DateTimeOffset conversion
- Find implicit culture-sensitive ToString in concatenation
- Find implicit record class declaration
- Find integer 0 used instead of named enum value
- Find interpolated string without parameters
- Find method that is too long
- Find missing NotNullIfNotNull attribute
- Find missing langword in XML comment
- Find missing non-generic interface implementation
- Find missing string equality comparer
- Find multi-line XML doc comment style
- Find multi-line XML doc comments
- Find non-constant string.Format format string
- Find non-deterministic end-of-line in strings
- Find non-flags enum with [Flags]
- Find null passed for CancellationToken
- Find override method missing params keyword
- Find overrides that change parameter defaults
- Find overwritten parameter values
- Find potentially invalid attribute argument type
- Find raw string with implicit end of line
- Find reassigned primary constructor parameter
- Find redirect without UseShellExecute=false
- Find redundant default argument values
- Find redundant nameof with CallerArgumentExpression
- Find static event with non-null sender
- Find static members on generic types
- Find string method missing StringComparison
- Find string.GetHashCode() usage
- Find struct member that could be readonly
- Find throw statements in finalizer
- Find type name matching namespace
- Find type with BCL name
- Find unawaited task in using statement
- Find unawaited task return in using block
- Find unobserved async call result
- Find virtual method call in constructor
- Fix invalid argument null check
- Flag duplicate enum value
- Implement exception constructors
- Implement non-generic counterpart
- Make class sealed
- Make class static
- Make field read-only
- Make method an extension method
- Mark local variable as const
- Mark type with DebuggerDisplay attribute
- Merge preprocessor directives
- Non-constant static fields should not be visible
- Normalize format of enum flag value
- Obsolete attribute should include explanation
- Order modifiers
- Order named arguments by parameters
- Order type parameter constraints
- Overriding member should not change 'params' modifier
- Parameter name differs from base
- Parenthesize not pattern for clarity
- Place constant values on right side of comparisons
- Prefer null check over type check
- Remove unused parameter
- Remove unused type parameter
- Simplify boolean logic with constants
- Sort enum members
- Split variable declaration
- Static member in generic type should use a type parameter
- Types should not extend ApplicationException
- Use 'this' for event sender
- Use 'var' or explicit type
- Use AttributeUsageAttribute
- Use EventArgs.Empty
- Use EventArgs.Empty instead of null
- Use EventHandler<T>
- Use OperatingSystem methods instead of RuntimeInformation
- Use System.Threading.Lock instead of object for locking
- Use async/await when necessary
- Use auto property
- Use block body or expression body
- Use coalesce expression
- Use collection expression
- Use constant instead of field
- Use element access
- Use enum field explicitly
- Use explicit type instead of var
- Use explicitly typed array
- Use file-scoped namespace
- Use method chaining
- Use method group conversion
- Use predefined type
- Use primary constructor
- Use read-only auto property
- Use string.Contains instead of IndexOf comparison
- Use string.IsNullOrEmpty method
- Use string.Length instead of comparison with empty string
- Use using declaration
- Use var instead of explicit type in foreach
- Validate arguments correctly
- Value type is never equal to null