Description
TheGetAttributes().Any(a => ...) pattern and foreach loops over GetAttributes() are verbose. ANcpLua.Roslyn.Utilities provides the HasAttribute() extension method for cleaner attribute checks.
Bad Code
Good Code
Properties
- Category: Usage
- Severity: Info
- Enabled by default: True
- Code fix available: False
Configuration
Notes
TheHasAttribute() extension method:
- Accepts attribute name with or without “Attribute” suffix
- Supports fully qualified type names
- More efficient than LINQ with
Any() - Works with any
ISymbolthat can have attributes
