我目前正在努力实现以下目标:我有一个接口这个接口:public interface IRepository<TEntity>{ //Some Methods}然后我有另一个接口扩展了上面的接口:public interface IAttractionRepository : IRepository<Attraction>{ //More methods}最后,我有一个实现(也实现了其他接口):public class AttractionRepository : ISomethingElse, IAnotherSomethingElse, IAttractionRepository{ //Implementations and methods}我想要实现的是:提供类型 AttractionRepository,我想搜索它的接口并获取扩展接口 IRepository 的接口。我的代码如下:Type[] interfaces = typeof(AttractionRepository).GetInterfaces(); //I get three interfaces here, which is fine.Type iface = null;foreach (Type t in interfaces) //Iterate through all interfaces foreach(Type t1 in t.GetInterfaces()) //For each of the interfaces an interface is extending, I want to know if there's any interface that is "IRepository<Attraction>" if (t1.IsSubclassOf(typeof(IRepository<>).MakeGenericType(typeof(Attraction)))) //Always false iface = t;我尝试了其他几种解决方案,但没有成功。
1 回答
- 1 回答
- 0 关注
- 96 浏览
添加回答
举报
0/150
提交
取消