Skip to main content
.NETFramework2.0.NETFramework3.5.NETFramework4.0.NETStandard1.0.NETStandard1.3.NETCoreApp3.1

Argument validation like: Guard.NotNull, Guard.NotNullOrEmpty, Guard.NotNullOrWhiteSpace, Guard.Condition en Guard.HasNoNulls.

Published
Jun 12, 2025
1y ago
Total Downloads
71.2M
71,174,229

Install

dotnet add package Stef.Validation --version 0.2.0-preview-01
ProductVersions
.NET
net5.0net6.0
.NET Standard
netstandard1.0netstandard1.3netstandard2.0netstandard2.1
Other
.NETCoreApp3.1.NETFramework2.0.NETFramework3.5.NETFramework4.0

README

Stef.Validation

Guard methods for argument validation (NotNull, NotEmpty, ...)

Usage example Stef.Validation

using Stef.Validation;

public Person(string name, int age)
{
    Guard.NotNullOrEmpty(name, nameof(name));

    Guard.NotNullOrEmpty(name); // It's also possible to omit the `nameof(...)`-statement because CallerArgumentExpression is used internally.

    Guard.Condition(age, a => a > 0, nameof(age));
}

Usage example Stef.Validation.Options

This package provides an extension method to validate options using data annotations. It is useful when you want to ensure that your options are correctly configured at startup.

Define options class

public class MyOptions
{
    [Required] // This attribute ensures that the Name property is not null or empty
    public required string Name { get; init; }
}

Validate options

using Stef.Validation.Options;

public static IServiceCollection Register(this IServiceCollection services, MyOptions options)
{
    Guard.NotNull(services);
    Guard.NotNull(options);

    // Add the options to the service collection. And throw an exception if the options are not valid.
    services.AddOptionsWithDataAnnotationValidation(options);
}

Changes from Previous Version

No structural changes between v0.1.1 and v0.2.0-preview-01.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 10 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.