J D
J D

Reputation: 48687

Creating anonymous record types at run-time

F# provides reflection that let's you, amongst other things, generate new values of function, tuple, record and union types at run-time. However, I cannot see anything in that module pertaining to anonymous records.

Is it possible to create new values of anonymous record types at run-time in F#?

Upvotes: 4

Views: 306

Answers (1)

Fyodor Soikin
Fyodor Soikin

Reputation: 80754

The FSharp.Reflection.FSharpValue.MakeRecord method works for anonymous records just as well as for nominal ones:

let x = {| a = "b"; c = 42 |}
ley y = FSharp.Reflection.FSharpValue.MakeRecord( x.GetType(), [| "foo"; 5 |] )

> val it : obj = {a = "foo"; c = 5;}

Or did I misunderstand the question?

Upvotes: 6

Related Questions