Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C# : Reflection question

  • 13-02-2004 01:18PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 79 ✭✭tendofan


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

    Tendofan


  • Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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