为什么成员不是引用的抽象类/接口的一部分? [英] Why is member not part of the abstract class/interface being referenced?

查看:90
本文介绍了为什么成员不是引用的抽象类/接口的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

 [ContractClass(typeof(TestCC))] 
interface ITest
{
bool Foo1< T>();
bool Foo2();
void Bar< T>();
}

[ContractClassFor(typeof(ITest))]
抽象类TestCC:ITest
{
public bool Foo1< T>()
{
抛出新的NotImplementedException();
}

public bool Foo2()
{
throw new NotImplementedException();
}

public void Bar< T>()
{
Contract.Ensures(Foo1< T>());
Contract.Ensures(Foo2());
抛出新的NotImplementedException();
}
}

ccrewrite失败,并显示一条错误消息,指出"Contract class"TestCC'引用成员'TestCC.Foo1< type parameter.T>'这不是被注释的抽象类/接口的一部分。"


由于Contract.Ensures(Foo2())很好但不是Constract.Ensures(Foo1< ; T>()),它似乎与泛型类型参数T有问题。为什么呢?


解决方案

感谢repro。我现在修好了。这确实是由于泛型而未处理的极端情况。


该修复程序将出现在下一版本中。



I have the following code:

    [ContractClass(typeof(TestCC))]
    interface ITest
    {
        bool Foo1<T>();
        bool Foo2();
        void Bar<T>();
    }

    [ContractClassFor(typeof(ITest))]
    abstract class TestCC : ITest
    {
        public bool Foo1<T>()
        {
            throw new NotImplementedException();
        }

        public bool Foo2()
        {
            throw new NotImplementedException();
        }

        public void Bar<T>()
        {
            Contract.Ensures(Foo1<T>());
            Contract.Ensures(Foo2());
            throw new NotImplementedException();
        }
    }

ccrewrite fails with an error message saying that "Contract class 'TestCC' references member 'TestCC.Foo1<type parameter.T>' which is not part of the abstract class/interface being annotated."

Since Contract.Ensures(Foo2()) is fine but not Constract.Ensures(Foo1<T>()), it seems to have a problem with the generic type parameter T. Why is that?

解决方案

Thanks for the repro. I fixed this now. It was indeed a corner case not handled due to generics.

The fix will appear in the next release.


这篇关于为什么成员不是引用的抽象类/接口的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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