Building with Code Contracts?

前端 未结 2 2037
我在风中等你
我在风中等你 2020-12-15 20:36

I have the following method:

private void DoSomething(CoolClass coolClass)
{
    if (coolClass == null)
    {
        throw new ArgumentNullException(\"coolC         


        
2条回答
  •  醉酒成梦
    2020-12-15 21:07

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

    public class CustomContract
    {
        public static void Requires( 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.

提交回复
热议问题