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

前端 未结 2 795
长情又很酷
长情又很酷 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.

提交回复
热议问题