digitalmars.D.learn - Get list of public methods of struct
- tcak (15/15) Mar 09 2017 Is there any way to get list of public methods of a struct?
- Adam D. Ruppe (5/6) Mar 09 2017 You can loop through __traits(allMembers, YourStruct) and check
- Jonathan M Davis via Digitalmars-d-learn (7/13) Mar 09 2017 If there's any risk of the same function name being used for both public...
Is there any way to get list of public methods of a struct? I looked at both "traits" and "std.traits". getVirtualFunctions and getVirtualMethods are closest I guess, but they don't seem like general purpose due to "Virtual" part. (Wouldn't it work if a method was final?) I saw "FieldNameTuple" in std.traits, but that doesn't seem like a proper solution. I want to use a mixin and foreach to generate a piece of code, that selects which method to call based on given parameter. So, the generated code will be like, if( param == "woof" ) myStruct.woof(); else if( param == "meow" ) myStruct.meow(); woof and meow are the methods of defined struct.
Mar 09 2017
On Thursday, 9 March 2017 at 18:32:41 UTC, tcak wrote:Is there any way to get list of public methods of a struct?You can loop through __traits(allMembers, YourStruct) and check protection, type, etc. __traits(getMember, YourStruct, "some name") gets one method in particular. allMembers returns a list of name strings.
Mar 09 2017
On Thursday, March 09, 2017 18:48:22 Adam D. Ruppe via Digitalmars-d-learn wrote:On Thursday, 9 March 2017 at 18:32:41 UTC, tcak wrote:If there's any risk of the same function name being used for both public and private functions, then __traits(getOverloads, ...) is going to need to be used rather than getMember, since getMember only gives you one of the overloads. - Jonathan M DavisIs there any way to get list of public methods of a struct?You can loop through __traits(allMembers, YourStruct) and check protection, type, etc. __traits(getMember, YourStruct, "some name") gets one method in particular. allMembers returns a list of name strings.
Mar 09 2017