I'm upgrading our application to .NET 6 from .NET 3.1 Core and trying to use the new ArgumentNullException.ThrowIfNull();
But in our code, we do not only check for null but also for other things.
if (anyParam == null)
{
throw new ArgumentNullException(nameof(anyParam));
}
if (string.IsNullOrEmpty(stringParam))
{
throw new ArgumentException(nameof(stringParam));
}
if (intParam <= 0)
{
throw new ArgumentException(nameof(intParam ));
}
if (listParam.Count == 0)
{
throw new ArgumentException(nameof(listParam));
}
Since Rule CA2208 now wants to change all ArgumentException lines, which we have a lot of, this would be a lot of work.
I want to know is it only safe to replace pure null checks like in the first example, or what is it all checking for in case of different parameter types. Couldn't find the proper documentation.
I would like to replace as much as I can with:
ArgumentNullException.ThrowIfNull(anyParam);
ArgumentOutOfRangeException
for the int checks. – Slaver