Let's say I have a method:
public void SayHello(User user)
{
if (user == null)
throw new ArgumentNullException("user");
Console.Write(string.Format("Hello from {0}", user.Name));
}
It's clear that I should use ArgumentNullException as it shown above to validate that user is not null. Now how can I validate that user.Name is not empty? Would it be a good practice to do like that:
if (string.IsNullOrWhiteSpace(user.Name))
throw new ArgumentNullException("user", "Username is empty");