Skip to content

Instantly share code, notes, and snippets.

@kgiszewski
Created August 2, 2018 16:12
Show Gist options
  • Save kgiszewski/6535f033e754ed968b99c59e418e846e to your computer and use it in GitHub Desktop.
Save kgiszewski/6535f033e754ed968b99c59e418e846e to your computer and use it in GitHub Desktop.
Mandate
public static class Mandate
{
public static void That<TException>(bool condition, string message) where TException : Exception
{
if (!condition)
{
var exceptionInstance = (TException)Activator.CreateInstance(typeof(TException), message);
throw exceptionInstance;
}
}
}
@zpqrtbnk
Copy link

zpqrtbnk commented Aug 2, 2018

Cons: it will build and allocate the exception message string on each test, even when not throwing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment