如何通过字符串表单访问其字段名称?
我正在编译时弄清楚我要访问的对象的特定字段的名称。在编译之前,我不一定知道将是哪个字段,所以我只是将该字段名称作为字符串。如何利用NIM的元编程来访问对象上的该字段?
I'm figuring out at compile-time the name of a specific field of an object that I want to access. Before I compile, I do not necessarily know which field that is going to be, so I just have that field name as a string. How can I leverage nim's metaprogramming to access that field on the object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以编写一个非常简单的宏,该宏可以评估DOT表达式(又称对象。
这里是一个外观的示例:
仅当您在Compiletime 上知道字段(又称您作为静态字符串时)才能有效!请记住!
You can write a very simple macro that evaluates to a dot expression (aka object.yourFieldNameString).
Here an example of how that can look like:
This will only work if you know the field at compiletime (aka when you have it as a static string)! Keep that in mind!