Skip to content

Instantly share code, notes, and snippets.

@tunatoksoz
Created July 13, 2009 09:03
Show Gist options
  • Select an option

  • Save tunatoksoz/146005 to your computer and use it in GitHub Desktop.

Select an option

Save tunatoksoz/146005 to your computer and use it in GitHub Desktop.
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