Exemplo n.º 1
0
        /// <summary>
        /// Adds the specified behavior.
        /// </summary>
        /// <param name="behavior">The behavior.</param>
        public void Add(IBehavior behavior)
        {
            behavior.ThrowIfNull(nameof(behavior));

            // Try finding the entity behavior dictionary
            if (!_entityBehaviors.TryGetValue(behavior.Name, out var ebd))
            {
                ebd = new EntityBehaviorDictionary(behavior.Name);
                _entityBehaviors.Add(behavior.Name, ebd);
            }
            ebd.Add(behavior.GetType(), behavior);

            // Track lists
            foreach (var pair in _behaviorLists)
            {
                if (ebd.TryGetValue(pair.Key, out var b) && b == behavior)
                {
                    pair.Value.Add(b);
                }
            }
        }