typedefof operator

Category:
Data Types
Description: Demostrate how to use typedefof operator to create generic type.
Code:
let SampleTypeDefof() = 
let intType = typeof
let listType = typedefof>
let listIntType = listType.MakeGenericType(intType)
printfn "make a List type using typedefof operator."
printfn "the newly created type's full name is %s" (listIntType.FullName)

Execution Result:
make a List type using typedefof operator.
the newly created type's full name is System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]

Last edited Sep 14, 2011 at 2:29 AM by ttliu2000, version 1

Comments

elvincheng Jan 5, 2012 at 8:25 AM 
let SampleTypeDefof() =
let intType = typeof<int>
let listType = typedefof<System.Collections.Generic.List<_>>
let listIntType = listType.MakeGenericType(intType)
printfn "make a List type using typedefof operator."
printfn "the newly created type's full name is %s" (listIntType.FullName)