/// <summary> /// Method used to apply a value taking the specified LoadBehavior into account. /// </summary> /// <param name="o">The target object</param> /// <param name="value">The value to apply</param> /// <param name="member">The property to apply the value to</param> /// <param name="originalState">The original state map for the object</param> /// <param name="loadBehavior">The LoadBehavior to govern property merge behavior.</param> private static void ApplyValue(object o, object value, MetaMember member, IDictionary <string, object> originalState, LoadBehavior loadBehavior) { if (loadBehavior == LoadBehavior.KeepCurrent) { return; } Lazy <object> lazyValue = value as Lazy <object>; if (loadBehavior == LoadBehavior.RefreshCurrent) { // overwrite value with the new value if (lazyValue != null) { value = lazyValue.Value; } member.SetValue(o, value); } else if (loadBehavior == LoadBehavior.MergeIntoCurrent) { if (!PropertyHasChanged(o, originalState, member)) { // set the value only if our value hasn't been modified if (lazyValue != null) { value = lazyValue.Value; } member.SetValue(o, value); } } }