Prevent CodeContracts from hiding unused method parameters in resharper

Work on a large project using code contracts and a reseller.

Through many refactors, some method parameters are no longer required, but code contracts seem to hide this. eg

Maybe the source code was

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

However, due to refactoring, parameter 2 is no longer used / not assigned.

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

Without contracts, resharper will warn us that param2 is not used and can be removed. But with the conclusion of the contract, the code mistakenly believes that the parameter is actively used.

Is there a way to make resharper ignore the contract during development if this option is used or not?

+4
source share

Source: https://habr.com/ru/post/1650941/


All Articles