9.10.10

CodeContracts break encapsulation and Resharper 5.0 is blissfully unaware of them

Seems I have to make my helper methods public if I want to use them within a code contract, but I avoid this by defining a property with the private setter to end up with the Contract.Requires<TException>(…) implementation below:

Code Snippet
  1. public AbstractTrade Trade
  2. {
  3.     private set { _trade = value; }
  4.     get { return _trade; }
  5. }
  6.  
  7. public void Execute()
  8. {
  9.     Contract.Requires<TradingServiceException>(Trade.IsValid(),
  10.                                                "Trade execution failed");
  11.     if (TradeExecutedEvent != null)
  12.     {
  13.         TradeExecutedEvent(this, new TradeEventArgs(Trade));
  14.     }

C:\Sandbox\Pricing\CommodityServer\TradingService\TradeManager.cs(24,13): error CC1038: Member 'Zainco.Commodities.TradingService.TradeManager.get_Trade' has less visibility than the enclosing method 'Zainco.Commodities.TradingService.TradeManager.Execute'.
C:\Sandbox\Pricing\CommodityServer\TradingService\TradeManager.cs(24,13): warning CC1036: Detected call to method 'Zainco.Commodities.Interfaces.AbstractTrade.IsValid' without [Pure] in contracts of method 'Zainco.Commodities.TradingService.TradeManager.Execute'.
  elapsed time: 294.0169ms

No comments: