How to get instance member value from getSymbolsByUDA
Remi Thebault
remi.thebault at gmail.com
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
```d
struct Request
{
Method method;
string url;
int apiLevel;
}
@Request(Method.GET, "/my-resource/%s", 1)
struct MyResourceGet
{
@Param
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, ????);
}
unittest
{
MyResourceGet req;
req.name = "thisone";
assert(requestUrl(req) == "/my-resource/thisone");
}
```
In `requestUrl`, how do I actually get the value of `req.name`
from `paramsSymbols` and `req`?
More information about the Digitalmars-d-learn
mailing list