为了账号安全,请及时绑定邮箱和手机立即绑定

反射以获取类是否具有“实现”另一个接口的接口

反射以获取类是否具有“实现”另一个接口的接口

C#
qq_遁去的一_1 2021-07-01 09:00:05
我目前正在努力实现以下目标:我有一个接口这个接口: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
提交
取消
意见反馈 帮助中心 APP下载
官方微信