Determine if a member is a method

Jacob Carlborg doob at me.com
Wed Jan 1 04:13:39 PST 2014


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


More information about the Digitalmars-d-learn mailing list