Using reflection to find interfaces implemented

前端 未结 3 679
既然无缘
既然无缘 2020-12-06 00:06

I have the following case:

public interface IPerson { .. }    
public class Person : IPerson { .. }    
public class User : Person { .. }

相关标签:
3条回答
  • 2020-12-06 00:16

    See Implementations of interface through Reflection.

    0 讨论(0)
  • 2020-12-06 00:27

    Check the Type.IsAssignableFrom method.

    0 讨论(0)
  • 2020-12-06 00:37
    var control = _container.Resolve(objType); 
    var prop = viewType.GetProperty("SomeUser");
    if ((prop != null) && (prop.PropertyType.GetInterfaces().Contains(typeof(IPerson))) 
    { .. }
    
    0 讨论(0)
提交回复
热议问题