在C#中,我有一个使用generics传入T的函数,我想运行一个检查以查看T是否是一个object实现了一个interface,如果是的话调用那个interface上的methods之一。我不想让T约束只属于那种类型。可以这样做吗?例如:publicclassMyModel:IModelwhereT:MyObjectBase{publicIQueryableGetRecords(){varentities=Repository.Query();if(typeof(IFilterable).IsAssignableFrom(typeof(T))){//Filtermeisamethodt
我有接口(interface)IChild和IParent.IParent有一个成员是List.我希望有实现IParent的类每个类都有一个实现IChild的成员:publicinterfaceIChild{}publicinterfaceIParent{Lista{get;set;}}publicclassChildA:IChild{}publicclassChildB:IChild{}publicclassParentA:IParent{publicLista{get;set;}}publicclassParentB:IParent{publicLista{get;set;}}但是