示例#1
0
        private static bool TryMoveElements(ImmutableArray <ProjectItemElement> elements, ProjectItemElement referenceElement, MoveAction moveAction)
        {
            Requires.NotNull(referenceElement, nameof(referenceElement));

            ProjectElementContainer parent = referenceElement.Parent;

            if (parent == null || !elements.Any())
            {
                return(false);
            }

            // Sanity check
            bool didAllElementsMove = true;

            switch (moveAction)
            {
            case MoveAction.Above:
                foreach (ProjectItemElement element in elements)
                {
                    ProjectElementContainer elementParent = element.Parent;
                    if (elementParent != null)
                    {
                        elementParent.RemoveChild(element);
                        parent.InsertBeforeChild(element, referenceElement);
                    }
                    else
                    {
                        didAllElementsMove = false;
                    }
                }
                break;

            case MoveAction.Below:
                // Iterate in reverse order when we are wanting to move elements down.
                // If we didn't do this, the end result would be the moved elements are reversed.
                for (int i = elements.Length - 1; i >= 0; --i)
                {
                    ProjectItemElement element = elements[i];

                    ProjectElementContainer elementParent = element.Parent;
                    if (elementParent != null)
                    {
                        elementParent.RemoveChild(element);
                        parent.InsertAfterChild(element, referenceElement);
                    }
                    else
                    {
                        didAllElementsMove = false;
                    }
                }
                break;
            }

            return(didAllElementsMove);
        }
        private static void ProcessElementLocationOption(ProjectElementContainer container, ElementLocationOption option, ProjectElement element)
        {
            switch (option)
            {
            case ElementLocationOption.BeforeFirstChild:
            {
                ProjectElement firstChild = container.FirstChild;
                container.InsertBeforeChild(element, firstChild);
                break;
            }

            case ElementLocationOption.AfterLastChild:
            {
                ProjectElement lastChild = container.FirstChild;
                container.InsertAfterChild(element, lastChild);
                break;
            }

            default:
            {
                return;
            }
            }
        }