How can I create a record type in F# by using reflection? Thanks
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.