How do I get the name of a property from a property in C# (2.0)

后端 未结 7 685
春和景丽
春和景丽 2020-12-10 17:24

I know I could have an attribute but that\'s more work than I want to go to... and not general enough.

I want to do something like

class Whotsit
{
          


        
7条回答
  •  鱼传尺愫
    2020-12-10 17:45

    What you are trying to do is not possible. Using reflection you can:

    • Get a property, field or method's details from it's string name.
    • Get a list of all properties, fields or methods for a given type.

    Your GetName method, when called, is passed a string. The GetMethod will know about the string but retains no source property meta data.

    Out of interest, why are you trying to do this?

提交回复
热议问题