FXCop rule for "If X = Nothing" when X is an integer with zero value
1 Dim x as Integer? = Nothing
2 If x = Nothing Then
3 'this is what I think will happen
4 Else
5 'this is what really happens
6 End If
The correct way to write it is "If x is Nothing".
Is there an FXCop rule that checks this? Or better yet, can someone show me how to write my own?
Jonathan
+1
Jonathan Allen
source
to share
2 answers
Another good resource for writing custom FxCop rules can be found here: binarycoder
+1
Carl serrander
source
to share
The best way to learn how to write custom rules for FXCop is the forum here. It involves creating a custom assembly to parse the code and test it.
Specifically, you want to write a rule that says, βInstead of using = nothing for a nullable type, make sure you use hasvalue.
0
Rs conley
source
to share