Let's say I have interfaces IA and IB:
public interface IA {}
public interface IB : IA {}
Now I want list of classes which implement directly IA, but without those implementing IB and others interfaces that are inherited from IA.
If I have classes Foo and Bar:
public class Foo : IA {}
public class Bar : IB {}
I want my code to return only Foo class. I think I can do it via reflection. I have method that returns list of all classes implementing IA, but now I don't know what to do next.
var types = Assembly.Load("abc").GetTypes();
return types.Where(i => typeof(IA).IsAssignableFrom(i) && i.IsClass);
Aucun commentaire:
Enregistrer un commentaire