Property hiding and reflection (C#)

前端 未结 3 907
[愿得一人]
[愿得一人] 2020-12-11 00:53

Declaring a property in a derived class that matches the name of a property in the base class \"hides\" it (unless it overrides it with the override keyword).

3条回答
  •  甜味超标
    2020-12-11 01:19

    GetProperties is defined as all public properties of the type.

    You could get their get and set methods using:

    typeof(C).GetMethods()
             .Where(m => m.Name.StartsWith("set_") || m.Name.StartsWith("get_"))
    

    Although this seems like a bad idea, compared to going down the inheritance hierarchy to get the properties.

提交回复
热议问题