Skip to main content
ANcpLua.Roslyn.Utilities provides utilities for building Roslyn analyzers and source generators.

What’s New in v1.19

Expanded Guard API - Comprehensive argument validation:
  • Collections: NoDuplicates() for duplicate detection
  • File System: FileExists(), DirectoryExists(), ValidFileName(), ValidPath(), ValidExtension(), NormalizedExtension()
  • Type Validation: DefinedEnum(), NotNullableType(), AssignableTo<T>(), AssignableFrom<T>()
  • Member Validation: NotNullWithMember(), MemberNotNull() for object + member validation
  • Numeric: NotZero, NotNegative, Positive, NotGreaterThan, NotLessThan, LessThan, GreaterThan (int/long/double/decimal)
  • Double-specific: NotNaN(), Finite() for floating-point edge cases
  • Unreachable Code: Unreachable(), Unreachable<T>() with caller info capture
All numeric methods use [MethodImpl(AggressiveInlining)] for hot paths.

What’s New in v1.18

API cleanup - Tightened public surface, renamed methods for clarity:
  • Guard.NotNullOr* renamed to Guard.NotNullOrElse* with new lazy Func<T> overloads
  • IndentedStringBuilder.Indent()/Outdent() made private (use BeginBlock())
  • Helper extensions reorganized: NullableExtensions, ObjectExtensions, TryExtensions
  • Redundant nullability attributes and operators removed

Install

# For analyzers/generators (source-only, no runtime dependency)
dotnet add package ANcpLua.Roslyn.Utilities.Sources

# For polyfills only (no Roslyn dependency)
dotnet add package ANcpLua.Roslyn.Utilities.Polyfills

# For runtime reference
dotnet add package ANcpLua.Roslyn.Utilities

# For testing
dotnet add package ANcpLua.Roslyn.Utilities.Testing
Layer 0 Package: This package cannot depend on ANcpLua.NET.Sdk (circular dependency). Uses Microsoft.NET.Sdk with built-in polyfills.

Packages

PackageTargetDescription
ANcpLua.Roslyn.Utilitiesnetstandard2.0Core library (DLL reference)
ANcpLua.Roslyn.Utilities.Sourcesnetstandard2.0Source-only (embeds as internal in analyzers/generators)
ANcpLua.Roslyn.Utilities.Polyfillsnetstandard2.0Source-only polyfills (no Roslyn dependency)
ANcpLua.Roslyn.Utilities.Testingnet10.0Generator testing

Features

CategoryAPIsDocs
Flow ControlDiagnosticFlow<T>, ReportAndContinue()DiagnosticFlow
Pattern MatchingMatch.* (symbols), Invoke.* (operations)Patterns
Guard ClausesGuard.NotNull(), Guard.Positive(), etc.Guard
Semantic ValidationSemanticGuard<T>, MustBeAsync()SemanticGuard
Domain ContextsAwaitableContext, AspNetContextContexts
OperationsOperationExtensions, InvocationExtensionsOperations
Code GenerationIndentedStringBuilderCodegen
PipelineGroupBy(), Batch(), Distinct()Pipeline
Symbol ExtensionsIsEqualTo(), HasAttribute()Symbols
TestingTest<TGenerator>.Run(), caching validationTesting

Quick Example

// DiagnosticFlow - never lose diagnostics
symbol.ToFlow(nullDiag)
    .Then(ValidateMethod)
    .Where(m => m.IsAsync, asyncRequired)
    .WarnIf(m => m.IsObsolete, obsoleteWarn)
    .Then(GenerateCode)
    .ReportAndContinue(context);

// Pattern matching - replace 50-line if-statements
Match.Method()
    .Async()
    .ReturningTask()
    .WithCancellationToken()
    .Matches(method);