How to get instance member value from getSymbolsByUDA

Remi Thebault remi.thebault at
Sat Feb 26 10:39:18 UTC 2022

Hi all,

I'm trying to establish a REST API by using the type system (used 
in both client and server code).

Considering the code

struct Request
     Method method;
     string url;
     int apiLevel;

@Request(Method.GET, "/my-resource/%s", 1)
struct MyResourceGet
     string name;

     // other members...

string requestUrl(ReqT)(ReqT req) if (isRequest!ReqT)
     import std.format : format;
     import std.traits : getSymbolsByUDA;

     Request reqAttr = RequestAttr!ReqT;

     alias paramSymbols = getSymbolsByUDA!(ReqT, Param);
     // return format(reqAttr.url, ????);

     MyResourceGet req; = "thisone";
     assert(requestUrl(req) == "/my-resource/thisone");

In `requestUrl`, how do I actually get the value of `` 
from `paramsSymbols` and `req`?

More information about the Digitalmars-d-learn mailing list