Пример #1
0
        public CollectionVariation GenerateInverseDictionaryVariation(EditableCollection TargetCollection, char AlterCode, object[] Parameters)
        {
            var NewCode = GenerateInverseDictionaryAlterCode(AlterCode);
            var Result  = new CollectionVariation(TargetCollection, NewCode, Parameters);

            return(Result);
        }
Пример #2
0
        /// <summary>
        /// Generates inverse assignment or invocation for the supplied source variation and sense.
        /// </summary>
        public TVariation GenerateInverseVariation <TVariation>(TVariation SourceVariation, EEditOperationAction RequiredActionSense) where TVariation : Variation
        {
            TVariation GeneratedVariation = null;

            // If revert is required, then the call was made for the new undo registered in a currently executing redo.
            // This is the primary and original registration order (ready to be undone).
            // Else, if apply is required, then the call was made for the new redo registered in a currently executing undo.
            // This is the secondary registration order (ready to be redone).
            // In both cases the logic is the same.

            if (SourceVariation is AssignmentVariation)
            {
                var OriginalVariation = SourceVariation as AssignmentVariation;
                GeneratedVariation = (new AssignmentVariation(OriginalVariation.VariatingProperty, OriginalVariation.VariatingInstance,
                                                              OriginalVariation.VariatingValue)) as TVariation;
            }
            else
            if (SourceVariation is CollectionVariation)
            {
                // Notice that the inversion only will take place for "Apply" (intended for Redo), because collection variations are stored ready for Undo.

                /* if (RequiredActionSense == EEditOperationAction.Apply)
                 * { */

                CollectionVariation OriginalVariation = SourceVariation as CollectionVariation;

                if (OriginalVariation.VariatingCollection.GetType().Name == typeof(EditableList <>).Name)
                {
                    GeneratedVariation = GenerateInverseListVariation(OriginalVariation.VariatingCollection,
                                                                      OriginalVariation.VariatingAlterCode,
                                                                      OriginalVariation.PassedParameters) as TVariation;
                }
                else
                {
                    GeneratedVariation = GenerateInverseDictionaryVariation(OriginalVariation.VariatingCollection,
                                                                            OriginalVariation.VariatingAlterCode,
                                                                            OriginalVariation.PassedParameters) as TVariation;
                }

                /* }
                 * else
                 *  GeneratedVariation = SourceVariation; */
            }
            else
            {
                var OriginalVariation = SourceVariation as CommandVariation;
                var NewGroupVariation = new CommandVariation(OriginalVariation.CommandName,
                                                             OriginalVariation.AlterExistenceStatusWhileVariating);

                foreach (Variation RegVariation in OriginalVariation.Variations)
                {
                    var InverseVariation = GenerateInverseVariation(RegVariation, RequiredActionSense);

                    if (InverseVariation != null)
                    {
                        NewGroupVariation.AddVariation(InverseVariation);
                    }
                }

                NewGroupVariation.Variations.Reverse();
                GeneratedVariation = NewGroupVariation as TVariation;
            }

            return(GeneratedVariation);
        }