Is it recommended to throw an ArgumentNullException
when the concerned argument is not null
but one of its members is? For instance, if I have the following method:
public T Method(Blog blog)
{
if (blog.Posts is null)
{
throw new ArgumentNullException(paramName: nameof(blog.Posts));
}
}
For this method to complete its job, it requires that blog.Posts
must not be null
. Was the ArgumentNullException
intended to be used this way? Or would it be misleading? If so, is there another specific exception type that better suits this use case or should I just rely on the default NullReferenceException
?