4

Working on a large project making use of code-contracts and resharper.

Through numerous refactors some method parameters are no longer required, but code contracts appear to be hiding this. e.g.

Original code may have been

public foo( IMyInterface param1, IMyOtherInterface param2 )
{
    Contract.Requires<ArgumentNullException>( param1 != null );
    Contract.Requires<ArgumentNullException>( param2 != null );
    _param1 = param1
    _param2 = param2
}

However due to refactoing param 2 is no longer used / assigned.

public foo( IMyInterface param1, IMyOtherInterface param2 )
{
    Contract.Requires<ArgumentNullException>( param1 != null );
    Contract.Requires<ArgumentNullException>( param2 != null );
    _param1 = param1
}

Without the contracts, resharper would alert us that param2 is not being used, and could be removed. But with the contract in place the code mistakenly believes the parameter to be actively in use.

Is there any way to force resharper to ignore the contract while working out if the parameter is being used or not?

user3265613
  • 355
  • 2
  • 14
  • Not _actually_ `double`, right? Because value types (other than `Nullable<>`) are never null. – Andrew Aug 18 '16 at 15:20
  • No not double, I'll update the example to be more accurate, I was just playing with doubles at the time so they were the first thing to come to mind. – user3265613 Aug 18 '16 at 16:31

0 Answers0