Pages

Wednesday, August 31, 2011

Create generic type using F#

you can use typeof operator to get a concrete type, just like C#'s typeof operator. But when thing comes to the generic type, it becomes different.

in C#, you can do: typeof(List<>), but in F#, if you do typeof> you will get List type. The solution is simple: you have to use typedefof>,this will give a generic type definition and you can use GenerateGenericType to create the concrete type. In summary: typeof: for get concrete type typedefof: get the generic type definition.

No comments: