Skip to content

Repository files navigation

Swevo.AutoGuard

NuGetNuGet DownloadsCILicense: MIT.NET 10 Ready

Compile-time guard clauses for .NET.

Apply [AutoGuard] to a partial class with a primary constructor, then decorate constructor parameters with guard attributes:

usingAutoGuard;[AutoGuard]publicpartialclassCreateOrderCommand([NotNull]stringid,[NotEmpty]stringcustomer,[InRange(1,100)]intquantity,[Matches(@"^[A-Z0-9]+$")]stringsku){}

The source generator emits a private field initializer that validates arguments during construction and throws the expected framework exceptions.

Guard attributes

  • [NotNull]
  • [NotEmpty] for string and IEnumerable<T>
  • [InRange(min, max)]
  • [Matches(pattern)]

Package

  • Package ID: Swevo.AutoGuard
  • Target: Roslyn source generator / analyzer package
  • Assembly packed to analyzers/dotnet/cs

Also by the same author

🌐 Full suite overview: swevo.github.io

PackageDescription
AutoLog.GeneratorCompile-time high-performance logging — [Log(Level, Message)] generates LoggerMessage.Define. AOT-safe.
AutoHttpClient.GeneratorCompile-time typed HTTP client — [HttpClient] on an interface generates a strongly-typed client. AOT-safe Refit alternative.
AutoDispatch.GeneratorCompile-time CQRS dispatcher — [Handler] generates a strongly-typed IDispatcher. MediatR alternative.
AutoWireCompile-time DI auto-registration for Microsoft.Extensions.DependencyInjection.
AutoMap.GeneratorCompile-time object mapping with generated extension methods. AutoMapper alternative.

Related Packages

PackageDownloadsDescription
Swevo.AutoBusDownloadsFree, MIT-licensed in-process message bus for
Swevo.AutoBus.RabbitMQDownloadsRabbitMQ transport for AutoBus
Swevo.AutoAssertDownloadsFree, MIT-licensed fluent assertions for
Swevo.AutoAuthDownloadsA free, MIT-licensed fluent configuration wrapper around OpenIddict for building OAuth2/OIDC token servers in ASP
Swevo.AutoAuditDownloadsCompile-time audit field generation for EF Core entities using Roslyn source generators
Swevo.AutoResultDownloadsCompile-time Result monad for
Swevo.AutoImageDownloadsA free, MIT-licensed fluent image processing wrapper around SkiaSharp for
Swevo.AutoFeatureFlagDownloadsCompile-time feature flag stubs for
Swevo.AutoTestDataDownloadsCompile-time test data builders for

License

MIT

About

Compile-time guard clauses for .NET — [AutoGuard] + [NotNull]/[InRange]/[NotEmpty]/[Matches] generates ArgumentNullException/ArgumentOutOfRangeException checks from primary constructor parameters

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages