Code analyzers and fixes focusing on improving the performance of C# code.
Detect and fix common inefficiencies as you type. Supports C# 9 and later (Visual Studio 2019 and Visual Studio 2022).
Diagnostics in the Error List window are linked to online documentation (under construction).
Diagnostics include:
- Local variable can be inlined or declared const
- Stateless classes can be static
- Method can be declared static
- Avoid declaring methods used in delegate constructors static
- Public value types should implement equality
- Implement internal interfaces
- Await tasks correctly
- Do not call redundant functions
- Parentheses can be used to enable constant evaluation
- Async or iterator methods should avoid state machine generation for early exits (throws or synchronous returns)
- Internal leaf classes can be sealed
- Return types should be specific
- Parameter types should be specific
- Return types should not cause boxing
- Parameter types should not cause boxing
- Do not index an array multiple times within a loop body
- Use a CancellationToken when possible
- Initialized local should be used
- Local types should be specific
- Local types should not cause boxing
- Field types should be specific
- Field types should not cause boxing
- Do not create empty arrays
- Do not overwrite initialized variables
- Prefer readonly structs
- Avoid instantiating HttpClient
- Compare strings correctly
- Index strings correctly
- Do not use composite formatting to concatenate strings
- Do not append the result of string concatenation to a StringBuilder
- Do not append a single character string to a StringBuilder
- StringBuilders should be initialized with capacity
- Do not test strings for null when appending to a StringBuilder
- Do not append null or empty strings to a StringBuilder
- Do not append a substring to a StringBuilder
- Do not call string.IsNullOrEmpty() on a constant string
- Do not call string.IsNullOrEmpty() on a trimmed string
- Do not call string.IsNullOrEmpty() on a normalized string
- Do not call ToString() on an enum member
- Do not call Enum.GetName() on an enum member
- Use StringComparison.Ordinal where possible
- Prefer generic collections over non-generic ones
- Local collections should be initialized with capacity
- Use LINQ Count methods efficiently
- Use foreach efficiently
- Do not implicitly convert an IQueryable to an IEnumerable
- Do not query a LINQ EntitySet
- Do not use a LINQ where clause before filtering the query
- Do not aggregate the result of a LINQ select operation
- Do not call LINQ methods whose effect is undone by subsequent methods
- Use dictionaries efficiently
- Do not materialize an IEnumerable unnecessarily
- Avoid memory leaks
- Capture intermediate results in lambda expressions
- Use Contains instead of Any where possible
- Provide enough arguments to composite formatting
- Use the correct format syntax with composite formatting
| |