Reflecting over all properties of an interface, including inherited ones?

前端 未结 2 782
长情又很酷
长情又很酷 2020-12-11 15:32

I have an instance of System.Type that represents an interface, and I want to get a list of all the properties on that interface -- including those inherited from base inter

相关标签:
2条回答
  • 2020-12-11 15:53

    An answer of sorts is to be found in an annotation to the .NET framework version 3.5-specific MSDN page on GetProperties(BindingFlags bindingFlags) :

    Passing BindingFlags.FlattenHierarchy to one of the Type.GetXXX methods, such as Type.GetMembers, will not return inherited interface members when you are querying on an interface type itself.

    [...]

    To get the inherited members, you need to query each implemented interface for its members.

    Example code is also included. This comment was posted by a Microsoftie, so I would say you can trust it.

    0 讨论(0)
  • 2020-12-11 16:08

    See here: GetProperties() to return all properties for an interface inheritance hierarchy

    I don't think it's possible to get all members without doing what you suggested (i.e. getting all the implementing interfaces.)

    0 讨论(0)
提交回复
热议问题