Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C# : Reflection question

Options
  • 13-02-2004 1:18pm
    #1
    Registered Users Posts: 15,443 ✭✭✭✭


    Here's one which is jut driving me up the wall.....

    with System.Reflection.MethodBase.GetCurrentMethod().Name I can get the name of the method the code is currently executing in.

    How do I similarly get the name of a property when executing is inside it?

    If I use teh same call as above, on property foo, I get back "get_foo" or "set_foo", which I *could* parse, but that just strikes me as blindingly stupid. What I want is a single method-call which will return "foo".

    Anyone any ideas?

    jc


Comments

  • Registered Users Posts: 79 ✭✭tendofan


    What about the PropertyInfo class in the System.Reflection Namespace?

    Tendofan


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    What about it indeed? :)

    I've been looking at it, and its an abstract class, which doesn't make it much use to me in and of itself, and I haven't been able to find anything useful about it.

    jc


  • Registered Users Posts: 79 ✭✭tendofan


    Oops, sorry!

    Looking around at it, if you use the GetCurrentMethod() method from within a get_ or set_ the MemberType property of the MethodBase object returned is "Method", which makes sense, since properties don't exist as such, but are really backed by get_ and/or set_ methods with the same name.

    Maybe parsing is the handiest way to go.

    Tendofan


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by tendofan
    Owhich makes sense, since properties don't exist as such, but are really backed by get_ and/or set_ methods with the same name.

    I was just wondering why MS went to all the trouble of creating property syntax etc (unlike say Java, where properties are created by having the correctly-named methods), and then not supply any reflection methods to reflect this.

    Thanks for the help tho.

    jc


Advertisement