Skip to content

donnytian/GuardIt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GuardIt

C# Object Guard Extensions.

Install

> dotnet add package GuardIt

Dependencies

.NETStandard 1.0

Examples

// Argument guard: throw ArgumentNullException or ArgumentException
_service = service.NotNullArg(nameof(service));
_name = name.NotNullOrWhiteSpaceArg(nameof(name));

// Operation guard: throw InvalidOperationException
var entity = _service.GetEntities().FirstOrDefault();
entity.InvalidOperationIfNull("Custom error message");
entity.InvalidOperationIf(e => !IsValid(e), () => "Another custom error message");

// Any other / custom exceptions
var obj = mapper.Take();
obj.ThrowIf(i => !IsValid(i), () => new MyCustomException("My error message."));

About

C# Object Guard Extensions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages