Esempio n. 1
0
        // TODO : Handle injection on changing children & parents
        public override sealed void Add(IGlyphComponent item)
        {
            if (Contains(item))
            {
                throw new ArgumentException("Component provided is already contained by this entity !");
            }

            Type type = item.GetType();

            if (Components.AnyOfType(type) && type.GetCustomAttributes(typeof(SinglePerParentAttribute)).Any())
            {
                throw new SingleComponentException(type);
            }

            var glyphObject = item as GlyphObject;

            if (glyphObject != null)
            {
                glyphObject.Resolver.Parent = null;
            }

            base.Add(item);

            if (glyphObject != null)
            {
                glyphObject.Resolver.Parent = this;
            }

            Schedulers.PlanComponent(item);

            if (_initialized)
            {
                item.Initialize();
            }

            if (_contentLoaded && item is ILoadContent loadingItem)
            {
                Task.Run(async() => await loadingItem.LoadContent(Resolver.Resolve <IContentLibrary>())).Wait();
            }
        }