Skip to content

NS2.Verify This is a Extensible fluent input validation framework.

Notifications You must be signed in to change notification settings

jnormen/NS2.Verify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

NS2.Verify

This is a Extensible fluent input validation framework.
Made for .Net, the solution uses .Net Core
Input validation is mostly boring and creates lots of repetable code. And sometime conditions that are hard to read. This framework is made to make input validation more fun, esier and save lots of time regarding reading validations etc.

public void AddUsername(string username)
{
            Ensure.That(nameof(username), username)
            .NotNull()
            .IsEmail();
}

You can simple extend it with your own validation rules for your objects.
Just add an extension for:

Validation<T>

Exmampel:
public static Validation IsNotDefault(this Validation< DateTime> item)

This verify framework will give you just that Validation< T > objects extension fluent validations methods. So int, string etc have their own validation methods.

Sampelcode of the StringValidationExtention

```javascript public static class StringValidationExtension { [DebuggerHidden] public static Validation NotShorterThan(this Validation item, int value) { if (item.Value.Length < value) throw new ArgumentOutOfRangeException($"InputParam '{item.ParameterName}' cannot be less than '{value}'");
		return item;
	}

	[DebuggerHidden]
	public static Validation<string> NotLongerThan(this Validation<string> item, int value)
	{
		if (item.Value.Length > value)
			throw new ArgumentOutOfRangeException($"InputParam '{item.ParameterName}' cannot be greater than '{value}'");

		return item;
	}

	[DebuggerHidden]
	public static Validation<string> NotNullOrEmpty(this Validation<string> item)
	{
		if (string.IsNullOrWhiteSpace(item.Value))
			throw  new ArgumentNullException($"Parameter '{item.ParameterName}' cannot be null or empty string!");
		return item;
	}

}

</code>
		
Based on an old framework we worked on 2008 when we talked abour Design By Contract in Swenug (Sweden .Net User group) and other forums. 
https://rogeralsing.com/2008/05/10/followup-how-to-validate-a-methods-arguments/

About

NS2.Verify This is a Extensible fluent input validation framework.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages