Пример #1
0
        public bool RemoveComponent(MyComponentBase component)
        {
            if (Contains(component))
            {
                component.OnBeforeRemovedFromContainer();
            }
            else
            {
                return(false);
            }

            if (m_components.Remove(component))
            {
                return(true);
            }
            foreach (var childComponent in m_components)
            {
                if (childComponent is IMyComponentAggregate)
                {
                    var childAggregate = (childComponent as IMyComponentAggregate);
                    if (childAggregate.ChildList.RemoveComponent(component))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #2
0
 public static void AddComponent(this IMyComponentAggregate aggregate, MyComponentBase component)
 {
     Debug.Assert(aggregate != component, "Can not add to itself!");
     if (component.ContainerBase != null)
     {
         component.OnBeforeRemovedFromContainer();
     }
     aggregate.ChildList.AddComponent(component);
     component.SetContainer(aggregate.ContainerBase);
     aggregate.AfterComponentAdd(component);
 }