Usually, if I had this:
public string Foo(string text) { return text.Substring(3); }
I would get CA1062: Validate arguments of public methods from code analysis. This would be fixed by modifying the code as such:
public string Foo(string text) { if (text == null) throw new ArgumentNullException("text"); else if (string.IsNullEmptyOrWhiteSpace(text) throw new ArgumentException("May not be empty or white space", "text") else if (text.Length < 3) throw new ArgumentException("Must be at least 3 characters long", "text"); return text.Substring(3); }
But now I want to use another tool to perform this check:
public string Foo(string text) { Validator.WithArgument(text, "text").NotNullEmptyOrWhitespace().OfMinLength(3); return text.Substring(3); }
since the method checks the argument, the code analysis rule is executed, but you still get warning CA1062 . Is there a way to suppress the code analysis rule for such cases without manually suppressing them each time or disabling this particular code analysis rule?
source share