GithubHelp home page GithubHelp logo

arunselvakumar / liteguard Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adamralph/liteguard

0.0 1.0 0.0 21.16 MB

The guard clause library that floats like a butterfly and stings like a butterfly

License: MIT License

Batchfile 3.90% C# 57.33% Pascal 38.77%

liteguard's Introduction

NuGet version NuGet version Build status

Why, it's lighter than air!

The guard clause library which stands out from the crowd like the faintest passing whisper.

You'll hardly know it's there!

Get it from NuGet or build from source.

Usage

public void Foo(Bar bar)
{
    Guard.AgainstNullArgument(nameof(bar), bar);
    Guard.AgainstNullArgumentProperty(nameof(bar), nameof(bar.Baz), bar.Baz);
    Guard.AgainstNullArgumentProperty(nameof(bar), "Baz.Bazz", bar.Baz.Bazz);

    // the rest of your method, nice and safe, wrapped in the protecting arms of LiteGuard
}

public void Foo<T>(T bar) where T : class
{
    Guard.AgainstNullArgument(nameof(bar), bar);
    ...
}

public void Foo<T>(T bar)
{
    Guard.AgainstNullArgumentIfNullable(nameof(bar), bar);
    ...
}

Why did I create it?

The aim of LiteGuard is to be the most simple, unambiguous and lightweight guard clause library available.

A very explicit DSL

The names of LiteGuard clauses are unambiguous to ensure correct usage. Misuse should be obvious.

public void Foo(Bar bar)
{
    var baz = GetBaz();
    Guard.AgainstNullArgument("baz", baz); // clearly incorrect - baz is not an argument
}

No fluent API

Some guard clause libraries provide a fluent API.

A fluent API requires the creation of objects which serve no purpose other than to provide an access point for the next method in the DSL. The creation of these objects decreases performance, increases memory usage and adds pressure to the garbage collector. It is my belief that a guard clause library has no business in doing this. It should use as few resources as possible and be eligible for use in as wide a set of applications as possible. I love a good fluent API but it has its places and a guard clause library is not one of them.

No business rule clauses

Many guard clause libraries provide a huge range of methods for determining whether arguments satisfy all manner of business rules.

In my opinion, it is not the job of a guard clause library to validate arguments against business rules. I believe the role of a guard clause library is to prevent method calls with null arguments or null argument values. Ideally, I'd like such things to be built into .NET languages. If that ever happens I will happily allow LiteGuard to retire gracefully to a small but comfortable home near the seaside with a carriage clock and a little Havanese.

Build from source

Clone this repo, navigate to your clone folder and execute build.cmd. The only prerequisite you need is .NET Core SDK 2.0.0.

build.cmd executes the default build targets which include compilation, test execution and packaging. After the build has completed, the build artifacts will be located in artifacts/output/.

For full usage details for build.cmd, execute build.cmd -?. See simple-targets-csx for more info.

Can I help to improve it and/or fix bugs?

Absolutely! Please feel free to raise issues, fork the source code, send pull requests, etc.

No pull request is too small. Even whitespace fixes are appreciated.


LiteGuard logo designed by Vanja Pakaski.

liteguard's People

Contributors

adamralph avatar davidssl avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.