Created
October 29, 2014 03:29
-
-
Save Nate-Wilkins/ea5ad87e9c50fc6311c0 to your computer and use it in GitHub Desktop.
Assert expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Taken from: http://stackoverflow.com/questions/15147305/get-string-representing-the-expression-used-as-function-argument-in-c-sharp