Ejemplo n.º 1
0
 public static void RegisterFunctionType <TType, TReturns>()
 {
     DelegateSupport._functions[typeof(TType)][DelegateSupport.GetTypes(new Type[]
     {
         typeof(TReturns)
     })] = ((object target, object[] parms, Delegate @delegate) => ((Func <TType, TReturns>)@delegate)((TType)((object)target)));
 }
Ejemplo n.º 2
0
 private static string GetTypes(MethodInfo mi)
 {
     return(DelegateSupport.GetTypes((from p in mi.GetParameters()
                                      select p.ParameterType).Concat(new Type[]
     {
         mi.ReturnType
     }).ToArray <Type>()));
 }
Ejemplo n.º 3
0
 public static void RegisterFunctionType <TType, T1, T2, T3, TReturns>()
 {
     DelegateSupport._functions[typeof(TType)][DelegateSupport.GetTypes(new Type[]
     {
         typeof(T1),
         typeof(T2),
         typeof(T3),
         typeof(TReturns)
     })] = ((object target, object[] parms, Delegate @delegate) => ((Func <TType, T1, T2, T3, TReturns>)@delegate)((TType)((object)target), (T1)((object)parms[0]), (T2)((object)parms[1]), (T3)((object)parms[2])));
 }
Ejemplo n.º 4
0
 public static void RegisterActionType <TType>()
 {
     DelegateSupport._functions[typeof(TType)][DelegateSupport.GetTypes(new Type[]
     {
         typeof(void)
     })] = delegate(object target, object[] parms, Delegate @delegate)
     {
         ((Action <TType>)@delegate)((TType)((object)target));
         return(null);
     };
 }
Ejemplo n.º 5
0
 public static void RegisterActionType <TType, T1, T2, T3>()
 {
     DelegateSupport._functions[typeof(TType)][DelegateSupport.GetTypes(new Type[]
     {
         typeof(T1),
         typeof(T2),
         typeof(T3),
         typeof(void)
     })] = delegate(object target, object[] parms, Delegate @delegate)
     {
         ((Action <TType, T1, T2, T3>)@delegate)((TType)((object)target), (T1)((object)parms[0]), (T2)((object)parms[1]), (T3)((object)parms[2]));
         return(null);
     };
 }
Ejemplo n.º 6
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));
    }