Example #1
0
        /// <summary>
        /// Returns an instruction according to specified type name
        /// </summary>
        /// <param name="instructionType">Type of instruction to generate</param>
        /// <returns>Corresponding instruction</returns>
        public static PatchInstruction MakeInstruction(string instructionType)
        {
            PatchInstruction resultPI = null;

            if (!string.IsNullOrEmpty(instructionType))
            {
                instructionType = String2.ToPascalCase(instructionType);

                string fullClassName = string.Format(_FORMAT_INSTRUCTION_CLASS, instructionType);

                // To solve culture issues ??
                ObjectHandle dynamicObject = Activator.CreateInstance(null, fullClassName, false, BindingFlags.CreateInstance, null, null, CultureInfo.InvariantCulture, null, null);

                if (dynamicObject != null)
                {
                    resultPI = dynamicObject.Unwrap() as PatchInstruction;

                    if (resultPI != null)
                    {
                        resultPI._Type = (InstructionName)Enum.Parse(typeof(InstructionName), instructionType, true);
                    }
                }
            }

            return(resultPI);
        }
Example #2
0
        ///<summary>
        ///
        ///                    Creates a new object that is a copy of the current instance.
        ///
        ///</summary>
        ///
        ///<returns>
        ///
        ///                    A new object that is a copy of this instance.
        ///
        ///</returns>
        ///<filterpriority>2</filterpriority>
        public object Clone()
        {
            PatchInstruction clonePi = MakeInstruction(_Type.ToString());

            clonePi._Enabled     = _Enabled;
            clonePi._FailOnError = _FailOnError;
            clonePi._Order       = _Order;
            clonePi._Parameters  = _CloneParameters();
            clonePi._Comment     = _Comment.Clone() as string;
            clonePi._Group       = _Group;

            return(clonePi);
        }
Example #3
0
        /// <summary>
        /// Utility method allowing to return an instruction with different type, but keeping all compatible parameters
        /// </summary>
        /// <param name="instruction"></param>
        /// <param name="newInstructionName"></param>
        /// <returns></returns>
        public static PatchInstruction ChangeInstruction(PatchInstruction instruction, InstructionName newInstructionName)
        {
            PatchInstruction changedInstruction = null;

            if (instruction != null)
            {
                changedInstruction             = MakeInstruction(newInstructionName.ToString());
                changedInstruction._Order      = instruction._Order;
                changedInstruction._Parameters = instruction._CloneParameters();
                changedInstruction._Comment    = instruction._Comment;
                changedInstruction._Group      = instruction._Group;
                changedInstruction.RemoveUnsupportedParameters();
            }

            return(changedInstruction);
        }
Example #4
0
        /// <summary>
        /// Copy properties from a patch instruction to another. References are copied, not values.
        /// </summary>
        /// <param name="piSource">Base instruction</param>
        /// <param name="piDestination">Target instruction</param>
        /// <param name="removeUnsupportedParameters">true to only keep parameters supported by target, false to keep all</param>
        public static void CopyProperties(PatchInstruction piSource, PatchInstruction piDestination, bool removeUnsupportedParameters)
        {
            if (piSource != null && piDestination != null)
            {
                piDestination._Enabled     = piSource._Enabled;
                piDestination._FailOnError = piSource._FailOnError;
                piDestination._Order       = piSource._Order;
                piDestination._Comment     = piSource._Comment;
                piDestination._Group       = piSource._Group;

                // Parameters: depending on boolean parameter
                piDestination._Parameters = piSource._Parameters;

                if (removeUnsupportedParameters)
                {
                    piDestination.RemoveUnsupportedParameters();
                }
            }
        }