I'd like to use a custom helper to simplify argument validation, something like this.
public static void ThrowIfNull(this object value, string parameterName)
{
if (value == null)
{
throw new ArgumentNullException(parameterName);
}
}
However, the static code analysis of course doesn't know that I do validate the input in public methods when using this helper, so it gives me CA1062
errors about public method arguments not being validated.
The particular issue is this one.
Is there a way to teach the code analyzer that this helper handles argument null validation? What is the proper solution for this issue?
try { string s = null; s.ThrowIfNull("s"); } catch (Exception ex) {/* set breakpoint here */ }
– Hormonal