Skip to main content
Source: AL0031UseOperationExtensionsAnalyzer.cs

Description

Manual checks on IOperation properties like TargetMethod.Name == and ConstantValue.HasValue && are verbose. ANcpLua.Roslyn.Utilities provides extension methods for cleaner operation analysis.

Bad Code

Good Code

Properties

  • Category: Usage
  • Severity: Info
  • Enabled by default: True
  • Code fix available: False

Configuration

Notes

The operation extension methods:
  • IsMethodNamed() - cleaner alternative to TargetMethod.Name == comparisons
  • TryGetConstantValue<T>() - type-safe constant extraction with null handling
  • Both reduce boilerplate in Roslyn analyzer implementations
  • Work with IInvocationOperation and IOperation respectively