.net - How to go from a discriminated union representation of a type to a System type for arrays? -


in f#, if want create system.type of say, array of strings, write typeof<string[]> , done it. because can specify type in typeof @ compile time.

type ty = | int32 | float32 | string | array of ty  let to_dotnet_type: ty -> system.type = ... 

but suppose had union type exact system.type looking unknown @ compile time, how go ty .net system.type? arrays in particular not have generic parameters guessing f# instantiating new array types inherit base system.array on demand. drawing blank on how dynamically.

the reason why being able move between internal representation , clr types beneficial because making language compiles f# (in f#) , using reflection functions such getmethod take arrays of system.types argument. using them interop lack of knowledge of better ways of doing it.

you can use type.makearraytype construct array types:

let rec to_dotnet_type: ty -> system.type = function | int32 -> typeof<int32> | float32 -> typeof<single> | string -> typeof<string> | array(elemty) -> let et = to_dotnet_type(elemty) in et.makearraytype() 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -