Glossary / Language analyzers
Language analyzers
Language analyzers are Roslyn analyzers focused on C# language constructs, compiler diagnostics, and source-level patterns. They can identify incorrect API use, suspicious control flow, nullable problems, performance pitfalls, and opportunities to adopt safer or clearer syntax; compiler diagnostics and analyzer diagnostics have distinct IDs and enforcement behavior.
Roslyn analysis model
Analyzers register callbacks for syntax nodes, symbols, operations, or compilation actions. Syntax analysis is fast and local; semantic/operation analysis understands types and overloads but may cost more. Code fixes can modify syntax trees while preserving formatting/trivia. Analyzers must be thread-safe and robust for incomplete IDE code, and should avoid blocking I/O or relying on machine-specific state.
Built-in .NET analyzers can be enabled through project settings, while packages provide additional rule sets. Severity and options can be configured in .editorconfig. Analyzer behavior may depend on language version, target framework, generated-code policy, and SDK. Security analyzers should be evaluated for coverage and false positives rather than treated as exhaustive protection.
Engineering guidance
Prefer analyzers that encode repeatable team standards or catch meaningful defects. Run the same versions in IDE and CI. For custom analyzers, test diagnostics, locations, code fixes, generated code, and incremental performance; package analyzers with compatible dependency versions.
Interview questions
- Syntax vs semantic analyzer? Syntax sees grammar shape; semantic analysis uses symbols/types and resolves meaning.
- What is an operation analyzer? It analyzes Roslyn's semantic operation tree for language-independent behavior patterns.
- Why analyzers need thread safety? Compiler/IDE may run analysis concurrently.
- How configure diagnostics?
.editorconfig, rulesets/props, and analyzer package settings. - What must custom analyzers avoid? Slow/blocking operations, nondeterminism, and assumptions about complete source.