Skip to content

JASGames/IsSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IsSharp

IsSharp is a guard clause library for C# that provides clean and fluent code with human readable exception messages using expression trees.

Install from Nuget or build using the source.

Example Usage

Guard.Is(() => CostPrice != null);
Guard.Is(() => CostPrice >= 25m && CostPrice <= 45m);
Guard.Is<InvalidConstraintException>(() => CostPrice == 30m);

Or

CostPrice.Is("Cost")
   	.NotNull()
   	.InRange(25m, 45m)
   	.Check(x => x > min && x < max)
   	.Check<ArgumentOutOfRangeException>(x => x == 30m);

Example Output

Guard.Is<NullReferenceException(() => CostPrice != null); // Throws NullReferenceException
/* CostPrice(null) should be not equal to null */

CostPrice.Is("Cost")
  .Check(x => x > min && x < max) // Throws ArgumentException
/* Cost(30) should be greater than min(5) and also Cost(30) should be less than max(10) */

Todo

  • Add more fluent methods ie GreaterThan, Whitespace etc
  • Add support for classes to the expression to text process
  • Add support for exception message verbose settings

About

C# guard clause library with expression

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages