how to execute the obj in list of object when obj is function

Category: visual studio fsharp

Question

Map to new space on Tue, 17 Feb 2015 09:50:21


how to execute the obj in list of object when obj is function

[<AllowNullLiteral>]
type DynamicType(objlist : obj list)=
    let value : List<obj> = new List<obj>();
    member this.Add(a : obj) =
        value.Add(a);
    static member FuncList(a : List<obj>, i : int) = 
        value.[i]()

if extend with "with", though it can append new function to class, it may need

to use reflection to find function if do not know which function in type


computing nightmare

Replies

Mr. Tines on Tue, 17 Feb 2015 10:43:58


If you know what function types you expect, then type-base matching is the way to go

    match object with
    | :? Type as value -> ... // do something with value