Beispiel #1
0
        /// <summary>
        /// Given a fully filled-out IObservedChange object, SetValueToProperty
        /// will apply it to the specified object (i.e. it will ensure that
        /// target.property == This.GetValue() and "replay" the observed change
        /// onto another object)
        /// </summary>
        /// <param name="target">The target object to apply the change to.</param>
        /// <param name="property">The target property to apply the change to.</param>
        public static void SetValueToProperty <TSender, TValue, TTarget>(
            this IObservedChange <TSender, TValue> This,
            TTarget target,
            Expression <Func <TTarget, TValue> > property)
        {
            object current = target;

            string[] propNames = RxApp.expressionToPropertyNames(property);

            PropertyInfo pi;

            foreach (var propName in propNames.SkipLast(1))
            {
                pi      = RxApp.getPropertyInfoOrThrow(current.GetType(), propName);
                current = pi.GetValue(current, null);
            }

            pi = RxApp.getPropertyInfoForProperty(current.GetType(), propNames.Last());
            pi.SetValue(current, This.GetValue(), null);
        }
Beispiel #2
0
 /// <summary>
 /// Given a fully filled-out IObservedChange object, SetValueToProperty
 /// will apply it to the specified object (i.e. it will ensure that
 /// target.property == This.GetValue() and "replay" the observed change
 /// onto another object)
 /// </summary>
 /// <param name="target">The target object to apply the change to.</param>
 /// <param name="property">The target property to apply the change to.</param>
 internal static void SetValueToProperty <TSender, TValue, TTarget>(
     this IObservedChange <TSender, TValue> This,
     TTarget target,
     Expression <Func <TTarget, TValue> > property)
 {
     Reflection.TrySetValueToPropertyChain(target, Reflection.Rewrite(property.Body).GetExpressionChain(), This.GetValue());
 }
 /// <summary>
 /// Given a fully filled-out IObservedChange object, SetValueToProperty
 /// will apply it to the specified object (i.e. it will ensure that
 /// target.property == This.GetValue() and "replay" the observed change
 /// onto another object)
 /// </summary>
 /// <param name="target">The target object to apply the change to.</param>
 /// <param name="property">The target property to apply the change to.</param>
 public static void SetValueToProperty <TSender, TValue, TTarget>(
     this IObservedChange <TSender, TValue> This,
     TTarget target,
     Expression <Func <TTarget, TValue> > property)
 {
     Reflection.SetValueToPropertyChain(target, Reflection.ExpressionToPropertyNames(property), This.GetValue());
 }