Esempio n. 1
0
        public static PropertyChangedEventHandler MakeWeak(this PropertyChangedEventHandler handler, Action <PropertyChangedEventHandler> unregister)
        {
            Validate(handler, unregister);
            var method_type = handler.Method.DeclaringType ?? throw new Exception($"method handler declaring type is null");
            var weh_type    = typeof(WeakPropChangedHandlerImpl <>).MakeGenericType(method_type);
            var cons        = weh_type.GetConstructor(new[] { handler.GetType(), unregister.GetType() }) ?? throw new Exception($"weak event handler constructor not found");
            var weh         = (IWeakPropChangedHandler)cons.Invoke(new object[] { handler, unregister });

            return(weh.Handler);
        }