Exemplo n.º 1
0
        /// <summary>
        /// Removes trait consumer
        /// </summary>
        /// <param name="traitConsumer">Trait consumer</param>
        internal void RemoveTraitConsumer([NotNull] TraitConsumer traitConsumer)
        {
            var requiredTraits = TypeCacher.consumerType2RequiredTypes[traitConsumer.GetType()];

            foreach (var traitType in requiredTraits)
            {
                traitManager[traitType].RemoveConsumer(traitConsumer);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds trait consumer in case providers of that trait exist
        /// </summary>
        /// <param name="traitConsumer">Trait consumer</param>
        /// <returns>True if consumer added, false otherwise</returns>
        internal bool AddTraitConsumer([NotNull] TraitConsumer traitConsumer)
        {
            var requiredTraits = TypeCacher.consumerType2RequiredTypes[traitConsumer.GetType()];

            if (requiredTraits.All(type => traitManager[type].AddConsumer(traitConsumer)))
            {
                return(true);
            }

            foreach (var requiredTrait in requiredTraits)
            {
                traitManager[requiredTrait].RemoveConsumer(traitConsumer);
            }
            return(false);
        }