通过反射创建 F# 记录
如何使用反射在 F# 中创建记录类型?谢谢
How can I create a record type in F# by using reflection? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何使用反射在 F# 中创建记录类型?谢谢
How can I create a record type in F# by using reflection? Thanks
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
您可以使用
FSharpValue.MakeRecord
[MSDN]< /a> 创建记录实例,但我认为 F# 中没有任何内容用于定义记录类型。但是,记录会编译为简单的类,因此您可以像在 C# 中一样构建类。TypeBuilder
[MSDN] 可能是一个很好的起点。更新
将
[]
添加到类型中即可使其成为记录。下面是如何在运行时执行此操作的示例。You can use
FSharpValue.MakeRecord
[MSDN] to create a record instance, but I don't think there's anything baked into F# for defining record types. However, records compile to simple classes, so you could build a class as you would in C#.TypeBuilder
[MSDN] may be a good starting point.UPDATE
Adding
[<CompilationMapping(SourceConstructFlags.RecordType)>]
to the type is all that's required to make it a record. Here's an example of how to do this at run-time.