• Stars
    star
    439
  • Rank 95,930 (Top 2 %)
  • Language
    C#
  • License
    MIT License
  • Created over 12 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Guard clause project for .NET

Ensure.That

Ensure.That is a simple guard clause argument validation lib, that helps you with validation of your arguments. It IS NOT for [insert your custom exception of choice here]. It aims at having an acceptable/good enough message (a bit like, take it or leave it) for devs (in logs etc) not for application users/systems etc. So no custom exceptions, messages or I18N support.

Build Status NuGet

Ensure.That - Using extension methods

Ensure.That(myString).IsNotNullOrWhiteSpace();
Ensure.That(myString, nameof(myString)).IsNotNullOrWhiteSpace();

Chainable:

Ensure
  .That(myString)
  .IsNotNullOrWhiteSpace()
  .IsGuid();

Easily extendable:

public static class StringArgExtensions
{
    public static StringParam IsNotFishy(this StringParam param)
        => param.Value != "fishy"
            ? param
            : throw Ensure.ExceptionFactory.ArgumentException("Something is fishy!", param.Name);
}

Ensure.That(myString, nameof(myString)).IsNotFishy();

NOTE: If you are worried that the constructed public readonly struct Param<T> {} created for the argument being validated will hurt your performance you can use any of the other constructs e.g. contextual Ensure.String or EnsureArg (see below for samples).

Ensure.Context - Using contextual validation

Introduced in the v7.0.0 release.

Ensure.String.IsNotNullOrWhiteSpace(myString);
Ensure.String.IsNotNullOrWhiteSpace(myString, nameof(myArg));

Easily extendable:

public static class StringArgExtensions
{
    public static string IsNotFishy(this StringArg _, string value, string paramName = null)
        => value != "fishy"
            ? value
            : throw Ensure.ExceptionFactory.ArgumentException("Something is fishy!", paramName);
}

Ensure.String.IsNotFishy(myString, nameof(myString));

EnsureArg - Using simple static methods

Introduced in the v5.0.0 release.

EnsureArg.IsNotNullOrWhiteSpace(myString);
EnsureArg.IsNotNullOrWhiteSpace(myString, nameof(myArg));

Easily extendable:

public static partial class EnsureArg
{
    public static string IsNotFishy(string value, string paramName = null)
        => value != "fishy"
            ? value
            : throw Ensure.ExceptionFactory.ArgumentException("Something is fishy!", paramName);
}

EnsureArg.IsNotFishy(myString, nameof(myString));

Samples

The Samples above just uses string validation, but there are more. E.g.:

  • Strings
  • Numerics
  • Collections (arrays, lists, collections, dictionaries)
  • Booleans
  • Guids

Get up and running with the source code

Unit-tests are written using xUnit and there are no integration tests, hence you should just be able to:

  • Pull
  • Compile
  • Run the tests

Easiest done using:

git clone ...

and

dotnet test src/

More Repositories

1

mycouch

MyCouch is the asynchronous CouchDB client for .NET
C#
228
star
2

SisoDb-Provider

SisoDb - Simple Structure Oriented Db
C#
126
star
3

mynatsclient

C# .NET and .NET Core client for NATS
C#
85
star
4

structurizer

Provide Structurizer with an object graph and it efficiently provides key-values for it.
C#
53
star
5

Kiwi

For embedding your GitHub Wiki locally, i.e in ASP.Net MVC
C#
46
star
6

routemeister

Simple async in process route library.
C#
41
star
7

requester

Requester is a Http-request fiddling magical something that is designed to interact with and help you validate web APIs.
C#
37
star
8

LiteCQRS

My small conventionbased CQRS solution in C#
C#
27
star
9

jsonnet-privatesetterscontractresolvers

Replaced with new repo and NuGets: https://github.com/danielwertheim/jsonnet-contractresolvers
PowerShell
22
star
10

lightnugetserver

Multi feed enabled, self hosted NuGet Server
C#
16
star
11

jsonnet-contractresolvers

Custom contract resolvers for Newtonsoft JSON.Net, supporting e.g. private setters and private constructors.
C#
14
star
12

dotnet-sqldb

.NET Core Global Tool using e.g. DbUp to apply Db migrations for SQL-Server
F#
11
star
13

myinfluxdbclient

Simple, async, client for InfluxDb
C#
10
star
14

digger

C#
9
star
15

PineCone

See Structurizer instead
C#
6
star
16

mycouch.aspnet.identity

MyCouch.AspNet.Identity - an ASP.Net identity provider for CouchDb and Cloudant
C#
6
star
17

tokenserver-adventures

My Playground for IdentityServer3 samples
JavaScript
5
star
18

PreCoord

Presentation Coordinator for Impress using WebSockets
JavaScript
3
star
19

nodejsreporter

Simple sample of using Node.js and Handlebars to create custom YouTrack report.
3
star
20

SisoDb-Benchmarks

C#
3
star
21

SisoDb-Samples

Just some small samples of how SisoDb can be used in some situations.
C#
2
star
22

rill

C#
1
star
23

serilog-sinks-azureappendblob

Serilog sink that logs to append blobs in an Azure Storage Account.
C#
1
star