Esempio n. 1
0
        public static IDisposable BindCommandToObject(ICommand command, object target, IObservable <object> commandParameter, string eventName)
        {
            var type   = target.GetType();
            var binder = bindCommandEventCache.Get(type);

            if (binder == null)
            {
                throw new Exception(String.Format("Couldn't find a Command Binder for {0} and event {1}", type.FullName, eventName));
            }

            var eventArgsType = Reflection.GetEventArgsTypeForEvent(type, eventName);
            var mi            = binder.GetType().GetTypeInfo().DeclaredMethods.First(x => x.Name == "BindCommandToObject" && x.IsGenericMethod);

            mi = mi.MakeGenericMethod(new[] { eventArgsType });

            //var ret = binder.BindCommandToObject<TEventArgs>(command, target, commandParameter, eventName);
            var ret = (IDisposable)mi.Invoke(binder, new[] { command, target, commandParameter, eventName });

            if (ret == null)
            {
                throw new Exception(String.Format("Couldn't bind Command Binder for {0} and event {1}", type.FullName, eventName));
            }

            return(ret);
        }