Ejemplo n.º 1
0
        public T Invoke(object arg0, object arg1, object arg2)
        {
            if (cache.TryGet(arg0, arg1, arg2, out var result))
            {
                return((T)result(arg0, arg1, arg2));
            }

            var ctor = Dispatch.BindToConstructor(typeof(T), new [] { arg0, arg1, arg2 });

            if (ctor != null)
            {
                var f = DelegateHelpers.GetMethodDelegate03(ctor);
                cache.CacheMethod(arg0, arg1, arg2, f);
                return((T)f(arg0, arg1, arg2));
            }
            throw new ArgumentException($"Could not invoke constructor `{typeof(T)}` with types {arg0.GetType()}, {arg1.GetType()}, {arg2.GetType()}.");
        }
Ejemplo n.º 2
0
        public object Invoke(object target, object arg0, object arg1)
        {
            if (cache.TryGet(target, arg0, arg1, out var result))
            {
                return(result(target, arg0, arg1));
            }

            var method = Dispatch.BindToMethod(BindingFlags.Public | BindingFlags.Instance, target.GetType(), MemberName, new [] { arg0, arg1 });

            if (method != null)
            {
                var f = DelegateHelpers.GetMethodDelegate03(method);
                cache.CacheMethod(target, arg0, arg1, f);
                return(f(target, arg0, arg1));
            }
            throw new ArgumentException($"Could not invoke instance member method `{MemberName}` on target {target.ToString()} ({target.GetType()}) with argument types {arg0.GetType()}, {arg1.GetType()}.");
        }
Ejemplo n.º 3
0
        public object Invoke(object arg0, object arg1, object arg2)
        {
            if (cache.TryGet(arg0, arg1, arg2, out var result))
            {
                return(result(arg0, arg1, arg2));
            }

            var method = Dispatch.BindToMethod(BindingFlags.Public | BindingFlags.Instance, Target, MemberName, new [] { arg0, arg1, arg2 });

            if (method != null)
            {
                var f = DelegateHelpers.GetMethodDelegate03(method);
                cache.CacheMethod(arg0, arg1, arg2, f);
                return(f(arg0, arg1, arg2));
            }
            throw new ArgumentException($"Could not invoke static method `{MemberName}` on type {Target} with argument types {arg0.GetType()}, {arg1.GetType()}, {arg2.GetType()}.");
        }