Created
July 13, 2009 09:03
-
-
Save tunatoksoz/146005 to your computer and use it in GitHub Desktop.
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
| public static class Guard | |
| { | |
| public static void NotNull(object item,string propName) | |
| { | |
| if(item==null) | |
| throw new ArgumentNullException(propName); | |
| } | |
| public static void NotNull(Expression<Func<object>> item) | |
| { | |
| if(item.Compile()()==null) | |
| throw new ArgumentNullException(((MemberExpression) item.Body).Member.Name); | |
| } | |
| public static void NotNullOrEmpty(Expression<Func<string>> item) | |
| { | |
| if (string.IsNullOrEmpty(item.Compile()())) | |
| throw new ArgumentNullException(((MemberExpression)item.Body).Member.Name); | |
| } | |
| public static void NotNullOrEmpty(string item,string name) | |
| { | |
| if (string.IsNullOrEmpty(item)) | |
| throw new ArgumentNullException(name); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment