合同和反思 [英] Contracts and reflection

查看:131
本文介绍了合同和反思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用System验证此代码的合同时:

When I verify contracts on this code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Diagnostics.Contracts;

namespace ContractTest
{
    public sealed class MyClass
    {
        public int MyProperty { get; set; }

        public void Test()
        {
            Contract.Requires(GetType() != null);
            Contract.Requires(GetType().GetProperties() != null );
            Contract.Requires(GetType().GetProperties().Length == 1);
        }

        public void Test2()
        {
            Test();
        }
    }
}



我得到了¥b $ b


I get

MyClass.cs(23,13): warning : CodeContracts: requires unproven
MyClass.cs(18,13): warning :   + location related to previous warning


它正在抱怨该行

It's complaining about the line

Contract.Requires(GetType().GetProperties().Length == 1);


我错过了什么或静态检查器无法根据反射验证约束?

Am I missing something or is the static checker unable to verify constraints based on reflection?

推荐答案

您好,是的,这是正确的,目前静态检查员不使用反射来验证合同。

左,
Hello,
  yes, it's correct, at the moment the static checker does not use reflection to validate contracts.

ciao,
f

这篇关于合同和反思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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