26. července 2005 13:33Is there or has anyone written a rule to check whether ByVal arguments are changed ?
1) In order to provide our developers with correct calling information in a call stack it is important that we have the original values.
2) If the developer was intending to pass information back to the caller this would highlight that it won't go.
Conversely - unchanged ByRef arguments.
If the value is never changed withing the method - why was it ByRef in the first place.
26. července 2005 16:57These are interesting ideas. The first one is bound to be noisy, there are many reasons why you might modify a value that's passed into a method, if only to avoid declaring a new variable. One good thing about the rule, however, is that it would always be possible to resolve it, you could always simply declare a new instance of the type. I wonder, though, how valuable this check would ultimately prove.
I think the second idea is stronger but, without flow analysis, it would only ever flag a method implementation that never touches a by ref argument. You would want to be sure not to flag an override (where a method declaration is mandated by the base class).
With flow analysis, you could write a rule that pointed out any code paths that would result in an untouched by ref value passed back to the caller). The FxCop custom rule SDK doesn't support this, though we're looking at adding it in the next version.