获得警告,'类型参数X隐藏接口X'

Cyf*_*r13 2 c# asp.net generics interface

这是在Visual Studio 2010中发生的.

我正在使用泛型方法,基本上失去了我的智能感知并阻止我继续这个项目的工作.

我基本上有以下课程:

public class SearchRepository : DataRepository<IAudit>
{
    public override IEnumerable<IAudit> RetrieveAll<IAuditSearch>(IAuditSearch searchParameters)
    {
        // CODE GOES HERE
    }

    public override bool Delete<TIAudit>(IAudit audit)
    {
        // CODE GOES HERE
    }
}
Run Code Online (Sandbox Code Playgroud)

这继承自:

public abstract class DataRepository<T>
{
    public virtual IEnumerable<T> RetrieveAll<U>(U parameter1)
    {
        throw new NotImplementedException();
    }

    public virtual bool Delete<U>(U parameter1)
    {
        throw new NotImplementedException();
    }
}
Run Code Online (Sandbox Code Playgroud)

所以删除工作正是我期望它工作的方式.我有intellisense,它编译正确.使用IAuditSearch,RetrieveAll无法正常工作.如果我将其更改为TIAuditSearch,那么它说我"没有合适的方法来覆盖".

不知道我做错了什么,但对我来说肯定不满意.

更新:更改虚拟以覆盖顶部的Delete方法.那是个错误.

Jef*_*ner 5

您隐式隐藏(通过不覆盖)方法签名

bool Delete<myType>(myType param) { ... }
Run Code Online (Sandbox Code Playgroud)

您可以克服错误我在派生类的Delete属性上引入"new"关键字.这明确隐藏了签名,让每个人都高兴,因为它说明了你的意图.

请阅读Microsoft文档:http://msdn.microsoft.com/en-us/library/aa691135%28v=vs.71%29.aspx.