Possible false positive for ValidateArgumentsOfPublicMethods
I added an == operator to a class. Its method signature is
publicstaticbooloperator ==(Table table1, Table table2).FxCop throws the ValidateArgumentsOfPublicMethods error and asks that I check the parameters for null. OK, so I did.
if( table1 == null ||
table2 == null )
{
return false;
}
FxCop is now happy. When I run my unit tests though, I get failures where the tests are throwing a StackOverflowException. Upon further analysis, it appears that testing for null within the == operator introduces an infinite recursion situation.
What is the best way to handle this?
[874 byte] By [
Joe2005] at [2008-2-15]
That is a great solution!
Although it appears to solve my problem, should this situation be considered a false positive for ValidateArgumentsOfPublicMethods as it is currently implemented?
If it flags this situation as a violation of the rule, should it not give advice similar to what you suggested above (only within the == operator method though)?
So my situation is actually a false negative for the DoNotOverloadOperatorEqualsOnReferenceTypes rule ? 
I sure like FxCop. I learn alot about coding each time I use it.
Thanks.
This is definitely a good approach, just thought I'd point out that the BCL already provides such a useful static helper:
if (Object.Equals(table1,
null)) return false;etc
Michael