コード例 #1
0
    public static object FastInvoke(this MethodInfo mi, object target, params object[] parameters)
    {
        Func <object, object[], object> func;

        if (DelegateSupport._methods.TryGetValue(mi, out func))
        {
            return(func(target, parameters));
        }
        string types;

        if (!mi.IsStatic && DelegateSupport._functions.ContainsKey(mi.DeclaringType) && DelegateSupport._functions[mi.DeclaringType].ContainsKey(types = DelegateSupport.GetTypes(mi)))
        {
            Delegate @delegate = DelegateSupport.ToOpenDelegate(mi);
            Func <object, object[], Delegate, object> inner = DelegateSupport._functions[mi.DeclaringType][types];
            Func <object, object[], object>           func2 = (object t, object[] p) => inner(t, p, @delegate);
            DelegateSupport._methods[mi] = func2;
            Func <object, object[], object> func3 = func2;
            return(func3(target, parameters));
        }
        return(mi.Invoke(target, parameters));
    }