Questo appartiene quasi a CodeReview. Ecco come affronterei questo in modo abbastanza pulito, senza controllare le cose due volte:
public void DoSomething(string obj1, string obj2)
{
CheckStrArgNotEmpty(name: "obj1", value: obj1);
CheckStrArgNotEmpty(name: "obj2", value: obj2);
// Optionally:
obj1 = obj1.Trim(); // obj1, obj2 are bad names btw
obj2 = obj2.Trim();
// The rest of the code ...
}
private static CheckStrArgNotEmpty(string argName, string value)
{
if (!String.IsNullOrWhitespace(value)) // or IsNullOrEmpty ?
{
return;
}
string exceptionMessage = String.Format(
"Argument named '{0}' is null or empty but it should not have been."
argName);
throw new ArgumentException(message: exceptionMessage);
}