/// <summary>
        ///     Sets the source value.
        /// </summary>
        /// <param name="targetAccessor">The specified accessor to get value.</param>
        /// <param name="context">The specified operation context.</param>
        /// <param name="throwOnError">
        ///     true to throw an exception if the value cannot be set.
        /// </param>
        protected override bool SetValueInternal(IBindingSourceAccessor targetAccessor, IDataContext context,
            bool throwOnError)
        {
            IBindingPathMembers members = _bindingSource.GetPathMembers(throwOnError);
            if (!members.AllMembersAvailable)
                return false;

            object penultimateValue = members.PenultimateValue;
            IBindingMemberInfo lastMember = members.LastMember;

            object oldValue;
            object newValue = targetAccessor.GetValue(lastMember, context, throwOnError);
            if (lastMember.CanRead)
            {
                oldValue = lastMember.GetValue(penultimateValue, null);
                if (ReferenceEquals(oldValue, newValue) || newValue.IsUnsetValueOrDoNothing())
                    return false;
            }
            else
            {
                oldValue = BindingConstants.UnsetValue;
                if (newValue.IsUnsetValueOrDoNothing())
                    return false;
            }

            ValueAccessorChangingEventArgs args = null;
            if (ValueChanging != null)
            {
                args = RaiseValueChanging(context, penultimateValue, lastMember, oldValue, newValue);
                if (args != null)
                {
                    if (args.Cancel)
                        return false;
                    if (!ReferenceEquals(newValue, args.NewValue))
                    {
                        newValue = args.NewValue;
                        if (newValue.IsUnsetValueOrDoNothing())
                            return false;
                    }
                }
            }
            newValue = BindingServiceProvider.ValueConverter(lastMember, lastMember.Type, newValue);
            if (Equals(oldValue, newValue))
                return false;
            if (BindingMemberType.Event.Equals(lastMember.MemberType))
            {
                TryRegisterEvent((BindingActionValue)oldValue, newValue, context);
                RaiseValueChanged(context, penultimateValue, lastMember, oldValue, newValue, args);
            }
            else
            {
                if (_closure != null)
                    _closure.Unsubscribe(false);
                lastMember.SetValue(penultimateValue, new[] { newValue });
                if (ValueChanged != null)
                    RaiseValueChanged(context, penultimateValue, lastMember, oldValue, newValue, args);
            }
            return true;
        }
        protected override bool SetValueInternal(IBindingSourceAccessor targetAccessor, IDataContext context,
                                                 bool throwOnError)
        {
            IBindingPathMembers members = _bindingSource.GetPathMembers(throwOnError);
            object penultimateValue     = members.PenultimateValue;

            if (penultimateValue.IsUnsetValue() || (penultimateValue == null && !members.AllMembersAvailable))
            {
                if (members.Path.IsDebuggable)
                {
                    DebugInfo($"Binding cannot set value for path {members.Path.Path}", new object[] { members });
                }
                return(false);
            }

            IBindingMemberInfo lastMember = members.LastMember;
            object             oldValue;
            object             newValue = targetAccessor.GetValue(lastMember, context, throwOnError);

            if (lastMember.CanRead && !BindingMemberType.BindingContext.EqualsWithoutNullCheck(lastMember.MemberType))
            {
                if (_disableEqualityChecking && !BindingMemberType.Event.EqualsWithoutNullCheck(lastMember.MemberType))
                {
                    oldValue = BindingConstants.UnsetValue;
                }
                else
                {
                    oldValue = lastMember.GetValue(penultimateValue, null);
                }
                if (ReferenceEquals(oldValue, newValue) || newValue.IsUnsetValueOrDoNothing())
                {
                    if (members.Path.IsDebuggable)
                    {
                        DebugInfo($"Binding ignores setter because old value: '{oldValue}' equals to new value '{newValue}'", new[] { members, oldValue, newValue });
                    }
                    return(false);
                }
            }
            else
            {
                oldValue = BindingConstants.UnsetValue;
                if (newValue.IsUnsetValueOrDoNothing())
                {
                    if (members.Path.IsDebuggable)
                    {
                        DebugInfo($"Binding ignores setter for value '{newValue}'", new[] { members, newValue });
                    }
                    return(false);
                }
            }

            ValueAccessorChangingEventArgs args = null;

            if (ValueChanging != null)
            {
                args = RaiseValueChanging(context, penultimateValue, lastMember, oldValue, newValue);
                if (args != null)
                {
                    if (args.Cancel)
                    {
                        return(false);
                    }
                    if (!ReferenceEquals(newValue, args.NewValue))
                    {
                        newValue = args.NewValue;
                        if (newValue.IsUnsetValueOrDoNothing())
                        {
                            if (members.Path.IsDebuggable)
                            {
                                DebugInfo($"Binding ignores setter for value '{newValue}'", new[] { members, newValue });
                            }
                            return(false);
                        }
                    }
                }
            }
            newValue = BindingServiceProvider.ValueConverter(lastMember, lastMember.Type, newValue);
            if (Equals(oldValue, newValue))
            {
                if (members.Path.IsDebuggable)
                {
                    DebugInfo($"Binding ignores setter because old value: '{oldValue}' equals to new value '{newValue}'", new[] { members, oldValue, newValue });
                }
                return(false);
            }
            if (BindingMemberType.Event.EqualsWithoutNullCheck(lastMember.MemberType))
            {
                TryRegisterEvent((BindingActionValue)oldValue, newValue, context, members);
                RaiseValueChanged(context, penultimateValue, lastMember, oldValue, newValue, args);
            }
            else
            {
                _closure?.Unsubscribe(false, _isOneTime);
                lastMember.SetSingleValue(penultimateValue, newValue);
                if (members.Path.IsDebuggable)
                {
                    DebugInfo($"Binding set value: '{newValue}' for source: '{penultimateValue}' with path: '{lastMember.Path}'", new[] { newValue, penultimateValue, lastMember });
                }
                if (ValueChanged != null)
                {
                    RaiseValueChanged(context, penultimateValue, lastMember, oldValue, newValue, args);
                }
            }
            return(true);
        }
        protected override bool SetValueInternal(IBindingSourceAccessor targetAccessor, IDataContext context,
                                                 bool throwOnError)
        {
            IBindingPathMembers members = _bindingSource.GetPathMembers(throwOnError);

            if (!members.AllMembersAvailable)
            {
                return(false);
            }

            object             penultimateValue = members.PenultimateValue;
            IBindingMemberInfo lastMember       = members.LastMember;

            object oldValue;
            object newValue = targetAccessor.GetValue(lastMember, context, throwOnError);

            if (lastMember.CanRead && !BindingMemberType.BindingContext.EqualsWithoutNullCheck(lastMember.MemberType))
            {
                oldValue = lastMember.GetValue(penultimateValue, null);
                if (ReferenceEquals(oldValue, newValue) || newValue.IsUnsetValueOrDoNothing())
                {
                    return(false);
                }
            }
            else
            {
                oldValue = BindingConstants.UnsetValue;
                if (newValue.IsUnsetValueOrDoNothing())
                {
                    return(false);
                }
            }

            ValueAccessorChangingEventArgs args = null;

            if (ValueChanging != null)
            {
                args = RaiseValueChanging(context, penultimateValue, lastMember, oldValue, newValue);
                if (args != null)
                {
                    if (args.Cancel)
                    {
                        return(false);
                    }
                    if (!ReferenceEquals(newValue, args.NewValue))
                    {
                        newValue = args.NewValue;
                        if (newValue.IsUnsetValueOrDoNothing())
                        {
                            return(false);
                        }
                    }
                }
            }
            newValue = BindingServiceProvider.ValueConverter(lastMember, lastMember.Type, newValue);
            if (Equals(oldValue, newValue))
            {
                return(false);
            }
            if (BindingMemberType.Event.EqualsWithoutNullCheck(lastMember.MemberType))
            {
                TryRegisterEvent((BindingActionValue)oldValue, newValue, context);
                RaiseValueChanged(context, penultimateValue, lastMember, oldValue, newValue, args);
            }
            else
            {
                if (_closure != null)
                {
                    _closure.Unsubscribe(false, _isOneTime);
                }
                lastMember.SetSingleValue(penultimateValue, newValue);
                if (ValueChanged != null)
                {
                    RaiseValueChanged(context, penultimateValue, lastMember, oldValue, newValue, args);
                }
            }
            return(true);
        }