Building with Code Contracts?

自作多情 提交于 2019-11-30 08:26:44

Why don't you just write your own version of the method, if you like the simplicity?

public class CustomContract
{
    public static void Requires<TException>( bool Predicate, string Message )
        where TException : Exception, new()
    {
       if ( !Predicate )
       {
          Debug.WriteLine( Message );
          throw new TException();
       }
    }
}  

Using Code Contracts just to have a friendly API sounds like shooting sparrows with a cannon.

NidhinSPradeep

By changing following project properties I could eliminate getting this exception while running.

Right click on project -> Properties -> Code Contract (Tab) change the assembley mode to "Standard Contract Requires" also select checkbox - Perform Runtime contract checking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!