This is mostly just out of curiosity, and is potentially a silly question. 🙂
I have a method like this:
public void MyMethod(string arg1, string arg2, int arg3, string arg4, MyClass arg5)
{
// some magic here
}
None of the arguments can be null, and none of the string arguments can equal String.Empty.
Instead of me having a big list of:
if(arg1 == string.Empty || arg1 == null)
{
throw new ArgumentException("issue with arg1");
}
is there a quicker way to just check all the string arguments?
Apologies if my question isn’t clear.
Thanks!
You can create or use frameworks to check contract of your method, e.g. Code Contracts.
Also you can create various utility methods like
ThrowIfNullOrEmptywho will encapsulate logic of checking arguments.