Determine if a member is a method

Orvid King blah38621 at gmail.com
Tue Dec 31 23:55:17 PST 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 at 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)?
>
>


More information about the Digitalmars-d-learn mailing list