https://github.com/dailydevops/guard
Basic input validation via the Requires class throws an ArgumentException, ArgumentNullException or other Exception types.
https://github.com/dailydevops/guard
assertion-library dotnet dotnet5 dotnet6 dotnet7 input-validation validation
Last synced: 2 months ago
JSON representation
Basic input validation via the Requires class throws an ArgumentException, ArgumentNullException or other Exception types.
- Host: GitHub
- URL: https://github.com/dailydevops/guard
- Owner: dailydevops
- License: mit
- Created: 2023-01-03T20:22:31.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-03T16:21:34.000Z (7 months ago)
- Last Synced: 2024-12-03T16:41:31.578Z (7 months ago)
- Topics: assertion-library, dotnet, dotnet5, dotnet6, dotnet7, input-validation, validation
- Language: C#
- Homepage:
- Size: 550 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# NetEvolve.Guard
This library provides a set of guard clauses to validate method parameters and object states in a fluent manner. For this purpose, the library provides the `Ensure`-class, which is a static class with a set of extension methods.
The usage is very simple and intuitive. The following example shows the basic usage of the `Ensure`-class.```csharp
public static bool Execute(string? directoryFolder)
{
string directory = Ensure.That(directoryFolder).IsNotNullOrWhiteSpace();
// or alternatively
string directory = Ensure.That(directoryFolder, nameof(directoryFolder)).IsNotNullOrWhiteSpace();// Do some magic
...
}
```
As you can see, the second parameter `parameterName` is optional and is automatically populated by .NET, based on the `CallerArgumentExpressionAttribute` functionality. This reduces the amount of code you have to write and makes the code more readable.## Compatibility
The following .NET TargetFrameworks are supported:
- .NET Standard 2.0
- .NET 5.0
- .NET 6.0
- .NET 7.0
- .NET 8.0