views:

215

answers:

2

Hi all,

When using Code Analysis and Code Contracts in combination, I get a lot of warnings like

warning : CA1062 : Microsoft.Design : In externally visible method 'Foo.Bar(Log)', validate parameter 'log' before using it.

In Foo.Bar, I have a Contract that validates 'log'.

public Bar(Log log){
   Contract.Requires(log != null);
   log.Lines.Add(...);
   ...
}

Is there a way to make FxCop understand Code Contracts?

/Staffan

+6  A: 

No I do not think it's possible in the current build as the code generated by the contracts rewriter does not produce the standard pattern that FxCop is looking for.

Typically though I disable this particular FxCop rule when using code contracts. I find the static verifier more than makes up for the loss of this rule as it will yell about a lack of checking much more aggressively than FxCop. I would suggest the same approach here which will fix this problem for you.

JaredPar
A: 

I expect that you could write an FxCop addin to do the job.

GaTechThomas