Skip to content

Instantly share code, notes, and snippets.

@wattsm
Last active December 20, 2015 04:19
Show Gist options
  • Save wattsm/6070114 to your computer and use it in GitHub Desktop.
Save wattsm/6070114 to your computer and use it in GitHub Desktop.
Create an F# sequence using reflection
let makeSeqOf itemType (items : obj list) =
let seqType =
makeGenericType
<| typedefof<List<_>>
<| [ itemType; ]
let sequence =
Activator.CreateInstance seqType
let add =
let addMethod =
seqType.GetMethod ("Add")
fun item ->
addMethod.Invoke (sequence, [| item; |])
|> ignore
items
|> List.iter add
sequence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment