public TBehavior GetBehavior <TBehavior>(BehaviorKey withKey) where TBehavior : IBehavior
        {
            Check.NotNull(withKey, nameof(withKey));
            Check.Requires <InvalidOperationException>(Contains(withKey));
            RequireNotSealed();

            BehaviorChainItemConfiguration item = GetItem(withKey);

            return((TBehavior)item.Instance);
        }
        /// <summary>
        ///   Adds a disabled behavior configuration to the top of the chain.
        /// </summary>
        internal void Prepend(BehaviorKey key, IBehavior instance)
        {
            Check.NotNull(key, nameof(key));
            Check.NotNull(instance, nameof(instance));
            RequireNotSealed();

            var item = new BehaviorChainItemConfiguration(key)
            {
                Instance = instance
            };

            _items.Insert(0, item);
        }
        /// <summary>
        ///   Calls the '<paramref name="configurationAction"/>' with the behavior
        ///   specified by '<paramref name="key"/>' that will be inserted in the
        ///   behavior chain. This method implicitly calls <see
        ///   cref="Enable"/>.
        /// </summary>
        /// <typeparam name="T">
        ///   The type of the behavior to configure. This may be the concrete type
        ///   of the behavior or a base type/interface.
        /// </typeparam>
        public void ConfigureBehavior <T>(
            BehaviorKey key,
            Action <T> configurationAction
            ) where T : IBehavior
        {
            Check.NotNull(key, nameof(key));
            Check.Requires <InvalidOperationException>(Contains(key));
            Check.NotNull(configurationAction, nameof(configurationAction));
            RequireNotSealed();

            BehaviorChainItemConfiguration item = GetItem(key);

            Enable(key);

            T behavior = (T)item.Instance;

            configurationAction(behavior);
        }