Should I Suppress CA1062: Check Public Method Arguments?

I recently upgraded my project to Visual Studio 2010 from Visual Studio 2008.

In Visual Studio 2008, this code analysis rule does not exist.

Now I'm not sure if I should use this rule or not.

I am creating an open source library, so it is important that people cannot make mistakes. However, if all I'm going to do is throw ArgumentNullException, when the parameter nullseems to be writing useless code, it ArgumentNullExceptionwill be thrown away even if I don't write this code.

EDIT: There is also a performance issue that needs to be resolved. Testing for nulleach public method can cause performance problems.

Should I remove this rule or fix the violation?

+5
source share
3 answers

It depends. The convention when using ArgumentNullException should include the name of the null argument in the description. In this way, the caller will know exactly what went wrong.

The source of the NullReferenceException (which is what will happen if you don't check) can be easily detected, but if the method is complicated, it can be more complicated. You may find yourself in a line of code where several links may be empty.

, ArgumentNullException, , .

: , , . , . ( ), . .

+6

, , . , , , , . -, , , , .

+3

№. . ( , , ).

, , - NullReferenceException() ? " , ( / ). , , .

: . , , . , - , - , . - , - .

, - . " " , .

. , , , , . 28 , , . , , O (n ^ 3), O (n ^ 2), ..

+2

All Articles