//Throw exception if parameters of function is null // eg: public Test(string input1) //{ // input1.ThrowIfArgumentIsNull("input1"); //} public static void ThrowIfArgumentIsNull(this T obj, string parameterName) where T : class { if (obj == null) throw new ArgumentNullException(parameterName + " not allowed to be null"); }
Monday, January 30, 2012
Best Extension Methods: Throw exception argument is Null
This extension method is for parameters of function where you wants that if a parameter/argument of a function is null then you want an exception to be thrown.
Share This!
Labels:
C#.NET,
Extension Methods
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment