Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating anonymous record types at run-time

Tags:

reflection

f#

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#?

like image 498
J D Avatar asked Sep 14 '25 19:09

J D


1 Answers

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?

like image 120
Fyodor Soikin Avatar answered Sep 17 '25 09:09

Fyodor Soikin