[英]Can't access properties of the base class of the class I am using as the type argument in a generic method
[英]Can't access functions in base generic class
我有一个带有服务引用的通用抽象基类。 当我尝试从具体的实现类访问任何属性时,收到以下错误。 “存储库”不包含“添加”的定义,也找不到找不到接受“存储库”类型的第一个参数的扩展方法“添加”(您是否缺少using指令或程序集引用?)
**Base class**
namespace Services
{
public abstract class BaseRepository<T> : IRepository<T>
{
public IService<T> _serviceContext;
public BaseRepository(IService<T> serviceContext)
{
_serviceContext = serviceContext;
}
#region IRepository<T> Members
public List<T> GetAll()
{
return _serviceContext.GetAll();
}
public T GetById(Guid id)
{
throw new NotImplementedException();
}
public void Add(T entity)
{
_serviceContext.Add(entity);
}
public void Remove(T entity)
{
throw new NotImplementedException();
}
#endregion
}
}
**Concrete class**
namespace Services
{
public class SpecialRepository : BaseRepository<SpecialItem>, ISpecialRepository
{
public SpecialRepository() : base(new DataAccess.SpecialList())
{
}
}
}
**Service Class**
namespace DataAccess
{
public class SpecialList : IService<SpecialItem>
{
public List<SpecialItem> GetAll()
{
//Implementation
}
}
}
**Repository Interface**
namespace Domain
{
public interface IRepository<T>
{
List<T> GetAll();
T GetById(Guid id);
void Add(T entity);
void Remove(T entity);
}
}
**Service Interface**
namespace DataAccess
{
public interface IService<T>
{
List<T> GetAll();
void Add(T entity);
}
}
任何帮助表示赞赏。 提前致谢!
您需要在SpecialList中定义一个Add方法。
我添加了一个,但没有收到错误消息
SpecialRepository rep = new SpecialRepository();
rep.Add(new SpecialItem());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.