Exemple #1
0
        protected IDisposable PerformTwoWay(TLeft left, TRight right, ISynchronizationContext context)
        {
            var leftEx3 = leftFunc.InvokeReversable(left);

            leftEx3.Successors.SetDummy();
            var rightEx3 = rightFunc.InvokeReversable(right);

            rightEx3.Successors.SetDummy();
            switch (context.Direction)
            {
            case SynchronizationDirection.CheckOnly:
                return(new IncrementalPropertyConsistencyCheck <TValue>(leftEx3, rightEx3, context));

            case SynchronizationDirection.LeftToRight:
            case SynchronizationDirection.LeftToRightForced:
                rightEx3.Value = leftEx3.Value;
                break;

            case SynchronizationDirection.LeftWins:
                if (leftEx3.Value != null)
                {
                    rightEx3.Value = leftEx3.Value;
                }
                else
                {
                    leftEx3.Value = rightEx3.Value;
                }
                break;

            case SynchronizationDirection.RightToLeft:
            case SynchronizationDirection.RightToLeftForced:
                leftEx3.Value = rightEx3.Value;
                break;

            case SynchronizationDirection.RightWins:
                if (rightEx3.Value != null)
                {
                    leftEx3.Value = rightEx3.Value;
                }
                else
                {
                    rightEx3.Value = leftEx3.Value;
                }
                break;

            default:
                throw new InvalidOperationException();
            }
            var dependency = new BidirectionalPropertySynchronization <TValue>(leftEx3, rightEx3);

            return(dependency);
        }
        protected IDisposable PerformTwoWay(TLeft left, TRight right, ISynchronizationContext context)
        {
            var leftEx3  = leftFunc.InvokeReversable(left);
            var rightEx3 = rightFunc.InvokeReversable(right);

            switch (context.Direction)
            {
            case SynchronizationDirection.LeftToRight:
            case SynchronizationDirection.LeftToRightForced:
                rightEx3.Value = leftEx3.Value;
                break;

            case SynchronizationDirection.LeftWins:
                if (typeof(TValue).IsValueType || leftEx3.Value != null)
                {
                    rightEx3.Value = leftEx3.Value;
                }
                else
                {
                    leftEx3.Value = rightEx3.Value;
                }
                break;

            case SynchronizationDirection.RightToLeft:
            case SynchronizationDirection.RightToLeftForced:
                leftEx3.Value = rightEx3.Value;
                break;

            case SynchronizationDirection.RightWins:
                if (typeof(TValue).IsValueType || rightEx3.Value != null)
                {
                    leftEx3.Value = rightEx3.Value;
                }
                else
                {
                    rightEx3.Value = leftEx3.Value;
                }
                break;

            default:
                throw new InvalidOperationException();
            }
            var dependency = new BidirectionalPropertySynchronization <TValue>(leftEx3, rightEx3);

            return(dependency);
        }