合同格式错误。发现分配后需要 - 合同涉及验证日期时间 [英] Malformed contract. Found Requires after assignment - contract involves verifying a DateTime

查看:60
本文介绍了合同格式错误。发现分配后需要 - 合同涉及验证日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多方法采用DateTime参数,使得唯一有意义的值是相对较新的值 - 换句话说,默认值或DateTime.MinValue肯定没有意义。所以,我写了这个:
$


Contract.Requires(whenDeactivated!= default(DateTime);



这行代码生成"分配后找到需要"消息,这显然是一个错误的错误。我已经尝试了各种解决这个问题的方法,没有一个明显的工作。请告诉我能做什么/应该做什么。
特定合同在我的代码中与大多数其他合同一样可取和必要。



示例方法的全文(在定义合同的抽象类中)对于接口)是:
$


     public void MassDeactivate(SQLiteConnection连接,字符串foreignKeyPropertyName,long foreignKeyValue,DateTime whenDeactivated)

     {

       Contract.Requires(connection!= null);

       Contract.Requires(!string.IsNullOrEmpty(foreignKeyProper) tyName));

            Contract.Requires(foreignKeyValue> default(long));

            Contract.Requires(whenDeactivated> default(DateTime));



           抛出新的NotImplementedException();

        }


谢谢,



乔治



I have a number of methods that take DateTime arguments such that the only values that make sense are relatively recent values - in other words, the default value or DateTime.MinValue definitely does not make sense. So, I wrote this:

Contract.Requires(whenDeactivated != default(DateTime);

And that line of code generates the "Found Requires after assignment" message, which is clearly a false error. I have tried various ways of working around this problem and none of the obvious ones work. Please advise on what I can / should do. That particular contract is as desirable and necessary in my code as most others.

The full text of an example method (in an abstract class defining contracts for an interface) is:

        public void MassDeactivate(SQLiteConnection connection, string foreignKeyPropertyName, long foreignKeyValue, DateTime whenDeactivated)
        {
            Contract.Requires(connection != null);
            Contract.Requires(!string.IsNullOrEmpty(foreignKeyPropertyName));
            Contract.Requires(foreignKeyValue > default(long));
            Contract.Requires(whenDeactivated > default(DateTime));

            throw new NotImplementedException();
        }

Thanks,

George


推荐答案

我会暂时避免默认(DateTime),直到我们解决此问题。

I would avoid the default(DateTime) for now until we fix this.


这篇关于合同格式错误。发现分配后需要 - 合同涉及验证日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆