Skip to content

Instantly share code, notes, and snippets.

@Nate-Wilkins
Created October 29, 2014 03:29
Show Gist options
  • Save Nate-Wilkins/ea5ad87e9c50fc6311c0 to your computer and use it in GitHub Desktop.
Save Nate-Wilkins/ea5ad87e9c50fc6311c0 to your computer and use it in GitHub Desktop.
Assert expression
[Conditional("DEBUG")]
public static void Assert(Expression<Func<bool>> assertion, string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
{
bool condition = assertion.Compile()();
if (!condition)
{
string errorMssage = string.Format("Failed assertion in {0} in file {1} line {2}: {3}", memberName, sourceFilePath, sourceLineNumber, assertion.Body.ToString());
throw new AssertionException(message);
}
}
@Nate-Wilkins
Copy link
Author

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