Пример #1
0
        /// <summary>
        /// Add an element to an existing group
        /// </summary>
        /// <param name="Group">Group to add an element to</param>
        /// <param name="Element">Element to add</param>
        /// <returns></returns>
        public static Group AddElement(Group Group, Element Element)
        {
            Group newGroup = new Group();
            newGroup.Name = Group.Name;
            List<Element> newGroupElements = Group.GroupElements;
            //check that the element doesn't already exist in the group
            if (!Group.GroupElements.Contains(Element))
            {
                newGroupElements.Add(Element);
            }
            else
            {
                throw new Exception("This element already exists in the group");
            }

            newGroup.GroupElements = newGroupElements;
            return newGroup;
        }
Пример #2
0
        /// <summary>
        /// Remove an element from a group
        /// </summary>
        /// <param name="Group">Group to remove element from</param>
        /// <param name="Element">Element to remove</param>
        /// <returns></returns>
        public static Group RemoveElement(Group Group, Element Element)
        {
            Group newGroup = new Group();
            newGroup.Name = Group.Name;
            List<Element> newGroupElements = Group.GroupElements;

            if (!Group.GroupElements.Contains(Element))
            {
                throw new Exception("This element is not in the group");
            }
            else
            {
                newGroupElements.Remove(Element);
            }
            newGroup.GroupElements = newGroupElements;
            return newGroup;
        }