Bug 23559 – Add trait to get members from symbol/module with filtering

Status
NEW
Severity
enhancement
Priority
P4
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-12-15T08:57:04Z
Last change time
2024-12-15T15:27:42Z
Assigned to
No Owner
Creator
Richard (Rikki) Andrew Cattermole
Moved to GitHub: dlang.org#4129 →

Comments

Comment #0 by alphaglosined — 2022-12-15T08:57:04Z
Adding a trait that allows returning alias symbols (like ``__traits(allMembers)``), but filtered for specific properties would allow for cutting down the costs of reflection code and make it more clear what it is doing. Proposal: ``` __traits(getMembers, symbolOrModuleName, filters) __traits(getMembersRecursive, symbolsOrModuleName, filters) ``` The difference between these two is one goes down nesting, and the other doesn't (shallow vs deep search). Filters are in the form of: ``struct | union | class | fields | function | import`` Ideally, this would be an expression so you can do or's and ands to require things like udas. But not required, only need to offer just one option at a time. Common use cases for this include registration of: web routes, ORM models, CLI handling routines. Preliminary agreement on worthiness by Walter: https://github.com/dlang/dmd/pull/14699#issuecomment-1352683461 This will require isStatic trait to be added to close https://issues.dlang.org/show_bug.cgi?id=16024
Comment #1 by robert.schadek — 2024-12-15T15:27:42Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dlang.org/issues/4129 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB