OfficeDev/PnP — pull request #103 by erwinvanhunen (2014-09-02 20:11:56+00:00)
Title: New Cmdlets, updated cmdlets and new validation for createtaxonomyfield methods

I added a new extension class and in there currently one extension method:

public static void ValidateNotNullOrEmpty(this T input, string variableName)
{
if (typeof(T) == typeof(string))
{
if (string.IsNullOrEmpty(input as string))
{
throw (input == null)
? new ArgumentNullException(variableName)
: new ArgumentException(Constants.EXCEPTION_MSG_EMPTYSTRING_ARG, variableName);
}
}
else if (typeof(T).IsSubclassOf(typeof(ClientObject)))
{
if (input == null || (input as ClientObject).ServerObjectIsNull == true)
{
throw new ArgumentNullException(variableName);
}
}
else
{
if (EqualityComparer.Default.Equals(input, default(T)))
{
throw new ArgumentException(variableName);
}

}
}

In methods this validation extension can be used alike:

public string DoSomethingWithString(string input, string another)
{
input.ValidateNotNullOrEmpty("input");
another.ValidateNotNullOrEmpty("another");
}

if 'input' is null or empty it will throw an exception. Specific case has been added to the validation code to handle CSOM classes.

@frankmarasco : Please test and/or provide feedback as you've been doing something similar in your code. I'm not 100% sold myself yet on the pattern, thinking of a way to do it in one line, like with a collection of variables or something or with an attribute class instead,see:

http://www.codinginstinct.com/2008/05/argument-validation-using-attributes.html