Пример #1
0
        private static IDisposable On <T>(HubConnection connection, T instance, MethodInfo method)
        {
            Type[] paramTypes = method.GetParameters().Select(p => p.ParameterType).ToArray();
            Func <object, object[], object> handler = FastInvokeHandler.Create(method);

            return(connection.On(method.Name, paramTypes, args => Task.Run(() => handler.Invoke(instance, args))));
        }
Пример #2
0
        private static void Subscribe <T>(IHubProxy proxy, T instance, MethodInfo method, ICollection <Action> disposer)
        {
            var subscription  = proxy.Subscribe(method.Name);
            var parmTypes     = method.GetParameters().Select(i => i.ParameterType).ToArray();
            var fastMethod    = FastInvokeHandler.Create(method);
            var invokeHandler = new Action <object[]>(parm => fastMethod.Invoke(instance, parm));
            Action <IList <JToken> > handler = args => OnData(parmTypes, args, proxy.JsonSerializer, invokeHandler);

            subscription.Received += handler;
            disposer.Add(() => subscription.Received -= handler);
        }