예제 #1
0
        public static IDisposable SubscribeWeakly <TSender, TProperty>(
            this TSender sender,
            Expression <Func <TSender, TProperty> > property,
            Action <TProperty> method)
            where TSender : class, INotifyPropertyChanged
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }

            var subscriber = method.Target;
            var methodInfo = method.Method;

            if (subscriber == null || methodInfo.IsStatic)
            {
                throw new InvalidOperationException("Static methods are not supported");
            }

            var propertyName = sender.GetPropertyName(property);
            var openHandler  = GetOpenHandler.FromEventAction <TProperty>(methodInfo);
            var getProperty  = property.Compile();

            return(sender.SubscribeWeakly(
                       subscriber,
                       (t, s, e) =>
            {
                if (e == null ||
                    string.IsNullOrEmpty(e.PropertyName) ||
                    string.Equals(e.PropertyName, propertyName))
                {
                    openHandler(t, getProperty.Invoke(s));
                }
            }));
        }
예제 #2
0
 public static IDisposable OnCustomDelegate <TEventHandler, TEvent>(
     Func <Action <object, TEvent>, TEventHandler> convertActionToHandler,
     Action <TEventHandler> subscribe,
     Action <TEventHandler> unsubscribe,
     Action <object, TEvent> method)
     where TEventHandler : class
     where TEvent : class
 {
     return(OnCustomDelegate(
                convertActionToHandler,
                subscribe,
                unsubscribe,
                method.Target,
                GetOpenHandler.FromEventHandler <TEvent>(method.Method)));
 }