From list of types A, B, C, ANotState, BNotState I want to get A, B,C that are marked with the interface. But if do get interfaces from ANotState or BNotState I've got only isState which is inherited from C (from ANotState in BNotState case).
Is there a way to know if the interface is implemented directly?
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
{
}
public class ANotState : C
{
}
public class BNotState : ANotState
{
}