Exemple #1
0
            /// <summary>
            ///     Gestiona los eventos de multiples propiedades.
            /// </summary>
            public RegisterForImp <TSender> RegisterProperties(Type[] propertyTypes, string[] propertyNames, Func <TSender, object>[] getValues,
                                                               EventHandler_v2 <PropertyChangedExEventArgs> eventHandler,
                                                               RegisterCallback <TSender, EventHandler_v2 <PropertyChangedExEventArgs> > register,
                                                               UnregisterCallback <TSender, EventHandler_v2 <PropertyChangedExEventArgs> > unregister,
                                                               bool valuesToManager = true)
            {
                ListenerManager.PropertiesListener listener = new ListenerManager.PropertiesListener(eventHandler,
                                                                                                     propertyTypes,
                                                                                                     propertyNames,
                                                                                                     getValues.Select(getValue => (Func <object, object>)(sender => getValue((TSender)sender))).ToArray(),
                                                                                                     (sender, h) => register((TSender)sender, h),
                                                                                                     (sender, h) => unregister((TSender)sender, h),
                                                                                                     valuesToManager);

                this.manager.Add <TSender>(listener);
                return(this);
            }
Exemple #2
0
            /// <summary>
            ///     Gestiona los eventos de una propiedad.
            /// </summary>
            public RegisterForImp <TSender> RegisterProperty <TItem>(string propertyName, Func <TSender, TItem> getValue,
                                                                     EventHandler_v2 <PropertyChangedExEventArgs> eventHandler,
                                                                     RegisterCallback <TSender, EventHandler_v2 <PropertyChangedExEventArgs> > register,
                                                                     UnregisterCallback <TSender, EventHandler_v2 <PropertyChangedExEventArgs> > unregister,
                                                                     bool valuesToManager = true)
            {
                ListenerManager.PropertyListener <TItem> listener = new ListenerManager.PropertyListener <TItem>(eventHandler,
                                                                                                                 propertyName,
                                                                                                                 sender => getValue((TSender)sender),
                                                                                                                 (sender, h) => register((TSender)sender, h),
                                                                                                                 (sender, h) => unregister((TSender)sender, h),
                                                                                                                 valuesToManager);

                foreach (ListenerManager.Listener aux in this.manager.FindListenersOfExactType(typeof(TSender)))
                {
                    if (aux is ListenerManager.PropertyListener)
                    {
                        ListenerManager.PropertyListener aux2 = (ListenerManager.PropertyListener)aux;
                        if (aux2.Compatible(listener))
                        {
                            ListenerManager.PropertiesListener newListener = ListenerManager.PropertiesListener.Join(aux2, listener);
                            this.manager.Remove <TSender>(aux2);
                            this.manager.Add <TSender>(newListener);
                            return(this);
                        }
                    }
                    else if (aux is ListenerManager.PropertiesListener)
                    {
                        ListenerManager.PropertiesListener aux2 = (ListenerManager.PropertiesListener)aux;
                        if (aux2.Compatible(listener))
                        {
                            ListenerManager.PropertiesListener newListener = ListenerManager.PropertiesListener.Join(aux2, listener);
                            this.manager.Remove <TSender>(aux2);
                            this.manager.Add <TSender>(newListener);
                            return(this);
                        }
                    }
                }

                this.manager.Add <TSender>(listener);
                return(this);
            }