Discussion:
reflect: find pointer receiver methods?
stephanos
2013-09-19 20:48:55 UTC
Permalink
I have a *reflect.Value* variable for a struct. I can access its methods
via *MethodByName().*

But how do I access the methods that work on the pointer receiver?


Cheers,
Stephan
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
roger peppe
2013-09-19 21:04:29 UTC
Permalink
v.Addr().MethodByName()

(assuming it's addressable)
otherwise you can use:

reflect.PtrTo(v.Type()).MethodByName()

but of course you can't call those methods on the original value.
I have a reflect.Value variable for a struct. I can access its methods via
MethodByName().
But how do I access the methods that work on the pointer receiver?
Cheers,
Stephan
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
stephanos
2013-09-20 07:51:34 UTC
Permalink
It works, thanks a lot! :)
Post by roger peppe
v.Addr().MethodByName()
(assuming it's addressable)
reflect.PtrTo(v.Type()).MethodByName()
but of course you can't call those methods on the original value.
I have a reflect.Value variable for a struct. I can access its methods
via
MethodByName().
But how do I access the methods that work on the pointer receiver?
Cheers,
Stephan
--
You received this message because you are subscribed to the Google
Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send
an
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Loading...