Bouncer – Lightweight Parameter Validation for .Net

Bouncer Framework

We’d like to introduce a dear friend of ours: Our open source framework Bouncer, available on GitHub.

Bouncer provides lightweight runtime-only “contracts” for .Net applications.
Its main use-case is to validate your parameters at the beginning of important methods.
This way you can easily catch all invalid parameters at runtime.
We use Bouncer in nearly all of our games.

The fastest way to explain Bouncer is to show it:

With Bouncer

IBouncer Bouncer;

public CreateNewUser(string name, int age)
{
  Bouncer.IsNotNullOrEmpty(name);
  Bouncer.IsPositive(age)
  // Do Stuff
}

Without Bouncer

public CreateNewUser(string name, int age)

{
  if (name == null)
  {
    throw new ArgumentNullException(nameof(name), "Must not be null.");
  }
  if (name.length == 0)
  {
    throw new ArgumentOutOfRangeException(nameof(name), "Must not be empty.");
  }
  if (age < 0)
  {
    throw new ArgumentOutOfRangeException(nameof(age), "Must be positive.");
  }
  
  // Do Stuff
}

Installation and Usage

As you can see, Bouncer is very easy to use and is compatible with pure .Net Core or .Net Framework projects via our NuGet package.
If you work in C#-compatible engines, such as Unity or CryEngine, we offer cross-platform .dll releases on GitHub.
Furthermore, Bouncer is compatible with Dependency Injection / IoC frameworks like Zenject, but can also be used statically by using Bouncer.Instance.

As we are only a duo of developers, we kept the project simple, but effective.
It is fully covered by unit tests and easily extensible.

Have fun improving your code quality with Bouncer!
If you have any issues or ideas, please feel free to create a new issue or get in touch on discord.