从类型 A、B、C、ANotState、BNotState 列表中,我想获取标有接口的 A、B、C。但是,如果确实从 ANotState 或 BNotState 获取接口,我只能得到从 C 继承的 isState(在 BNotState 情况下从 ANotState 继承)。
有没有办法知道接口是否是直接实现的?
public class Program
{
public static void Main()
{
List<Type> types = new List<Type>{typeof(A), typeof(B), typeof(C), typeof(ANotState), typeof(BNotState)};
//Now remove from list types that are not implementing isState interface directly which means ANotState and BNotState
}
}
public interface isState{}
public class A : isState
{
}
public abstract class B : A, isState
{
}
public abstract class C : B, isState
{ …Run Code Online (Sandbox Code Playgroud)