Пример #1
0
        /// <summary>
        /// clones simple properties and deeper trees
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public IqTarget DeepClone(IqTarget target)
        {
            var util = new IqTargetUtilities();

            //basic copy

            //TODO: the problem is here is we are creating an IqTargetBasic, which might not fit everyone's liking
            IqTarget copiedTarget = new IqTargetBasic();

            CopyTargetProperties(target, copiedTarget);

            //this returnes the copied tree
            var deepCopy = CloneIqTrees(target);

            //set root via private set
            copiedTarget.RootTarget = deepCopy.RootTarget;

            //set parent target
            copiedTarget.ParentTarget = deepCopy.ParentTarget;

            //set the child targets
            var childTargets = deepCopy.ChildTargets().ToList();

            if (deepCopy.HasChildren() && childTargets.Count > 0)
            {
                foreach (var subtarget in childTargets)
                {
                    copiedTarget.AddTarget(subtarget);
                }
            }

            return(copiedTarget);
        }
Пример #2
0
        /// <summary>
        /// for cloning a IqTarget. Recursive
        /// </summary>
        /// <param name="target">Input the root target so all children will be cloned</param>
        /// <returns></returns>
        public IqTarget Clone(IqTarget target)
        {
            IqTarget tempTarget = new IqTargetBasic();

            CopyTargetProperties(target, tempTarget);

            //child targets
            var childTargets = target.ChildTargets().ToList();

            if (target.HasChildren() && childTargets.Count > 0)
            {
                foreach (var child in childTargets)
                {
                    var clone = Clone(child);
                    clone.ParentTarget = target;
                    tempTarget.AddTarget(clone);
                }
            }
            return(tempTarget);
        }