digitalmars.D.learn - Determine if a member is a method
- Frustrated (5/5) Dec 31 2013 How does one determine if a member is a method and not anything
- Orvid King (12/17) Dec 31 2013 Well, unashamedly copying from my own code, I have a template defined th...
- Jacob Carlborg (5/13) Jan 01 2014 To find out if a member is a field you can iterate T.tupleof:
- Jacob Carlborg (6/9) Jan 01 2014 You mean the to get the full signature of a method? I don't think that's...
- Gary Willoughby (5/15) Jan 01 2014 I have some useful templates in the source of DUnit which does
- Dicebot (4/10) Jan 01 2014 Have a look at
- Frustrated (14/25) Jan 01 2014 There seems to be a bug. When I run it on a standard member it
- Dicebot (8/21) Jan 01 2014 Looks like it is an issue with return type which is template
How does one determine if a member is a method and not anything else? Also, how does one get the exact code string of a member instead of having to piece it together from info from std.traits? (which requires a lot of work)?
Dec 31 2013
Well, unashamedly copying from my own code, I have a template defined thusly: enum isMemberFunction(T, string member) = is(typeof(__traits(getMember, T.init, member)) == function); Where `T` is the type that `member` is a part of. You can also change `function` to any of class, interface, struct, enum, or union, do find out if the member is one of those. The only way I know of to determine if a member is a field though, is to determine that it is not a class, function, interface, struct, enum, or union. As to the second question, I suspect I'm failing at understanding what your asking, so I'll leave it to someone else (who's probably a bit more awake than I am) to answer that one. On 1/1/14, Frustrated <c1514843 drdrb.com> wrote:How does one determine if a member is a method and not anything else? Also, how does one get the exact code string of a member instead of having to piece it together from info from std.traits? (which requires a lot of work)?
Dec 31 2013
On 2014-01-01 08:55, Orvid King wrote:Well, unashamedly copying from my own code, I have a template defined thusly: enum isMemberFunction(T, string member) = is(typeof(__traits(getMember, T.init, member)) == function); Where `T` is the type that `member` is a part of. You can also change `function` to any of class, interface, struct, enum, or union, do find out if the member is one of those. The only way I know of to determine if a member is a field though, is to determine that it is not a class, function, interface, struct, enum, or union.To find out if a member is a field you can iterate T.tupleof: https://github.com/jacob-carlborg/mambo/blob/master/mambo/util/Reflection.d#L195 -- /Jacob Carlborg
Jan 01 2014
On 2014-01-01 08:43, Frustrated wrote:Also, how does one get the exact code string of a member instead of having to piece it together from info from std.traits? (which requires a lot of work)?You mean the to get the full signature of a method? I don't think that's possible, unless you can use __PRETTY_FUNCTION__ [1] somehow. [1] http://dlang.org/traits.html#specialkeywords -- /Jacob Carlborg
Jan 01 2014
On Wednesday, 1 January 2014 at 12:19:29 UTC, Jacob Carlborg wrote:On 2014-01-01 08:43, Frustrated wrote:I have some useful templates in the source of DUnit which does this. Take a look and customise for what you need: https://github.com/nomad-software/dunit/blob/master/source/dunit/reflection.d#L639Also, how does one get the exact code string of a member instead of having to piece it together from info from std.traits? (which requires a lot of work)?You mean the to get the full signature of a method? I don't think that's possible, unless you can use __PRETTY_FUNCTION__ [1] somehow. [1] http://dlang.org/traits.html#specialkeywords
Jan 01 2014
On 2014-01-01 08:43, Frustrated wrote:Have a look at https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/internal meta/codegen.d#L177 (cloneFunction) for inspiration (it is based on fullyQualifiedName from Phobos)Also, how does one get the exact code string of a member instead of having to piece it together from info from std.traits? (which requires a lot of work)?
Jan 01 2014
On Wednesday, 1 January 2014 at 15:10:56 UTC, Dicebot wrote:There seems to be a bug. When I run it on a standard member it works fine. When I run it on a property it throws an error src\phobos\std\traits.d(344): Error: forward reference of variable parentPrefix src\phobos\std\traits.d(505): Error: template instance std.traits.fullyQualifiedNameImplForSymbols!(Array!double) error instantiating src\phobos\std\traits.d(295): instantiated from here: fullyQualifiedNameImplForTypes!(Array!double, false, false, false, false) (admittedly it might not suppose be used on properties but it shouldn't crash and burn. Not sure if this is an issue with vibe.d or phobos)On 2014-01-01 08:43, Frustrated wrote:Have a look at https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/internal meta/codegen.d#L177 (cloneFunction) for inspiration (it is based on fullyQualifiedName from Phobos)Also, how does one get the exact code string of a member instead of having to piece it together from info from std.traits? (which requires a lot of work)?
Jan 01 2014
On Wednesday, 1 January 2014 at 17:19:01 UTC, Frustrated wrote:There seems to be a bug. When I run it on a standard member it works fine. When I run it on a property it throws an error src\phobos\std\traits.d(344): Error: forward reference of variable parentPrefix src\phobos\std\traits.d(505): Error: template instance std.traits.fullyQualifiedNameImplForSymbols!(Array!double) error instantiating src\phobos\std\traits.d(295): instantiated from here: fullyQualifiedNameImplForTypes!(Array!double, false, false, false, false) (admittedly it might not suppose be used on properties but it shouldn't crash and burn. Not sure if this is an issue with vibe.d or phobos)Looks like it is an issue with return type which is template struct/class. There is a long-standing bug with fullyQualifiedName in that regard: https://d.puremagic.com/issues/show_bug.cgi?id=10502 I am aware of that issue but don't have a good generic solution for it within existing D reflection tools. Properties on their own should work fine.
Jan 01 2014