Skip to main content
Source: AL0029UseHasAttributeAnalyzer.cs

Description

The GetAttributes().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

The HasAttribute() extension method:
  • Accepts attribute name with or without “Attribute” suffix
  • Supports fully qualified type names
  • More efficient than LINQ with Any()
  • Works with any ISymbol that can have attributes