/// <summary>
        ///   Returns a new <see cref="BehaviorChainTemplate"/> with the same
        ///   behavior chain item templates but with a different <see
        ///   cref="IBehaviorFactoryProvider"/>.
        /// </summary>
        public BehaviorChainTemplate OverrideFactoryProvider(IBehaviorFactoryProvider factoryProvider)
        {
            Check.NotNull(factoryProvider, nameof(factoryProvider));

            // The _itemTemplates list can be shared because we do not modify it.
            return(new BehaviorChainTemplate(factoryProvider, _itemTemplates));
        }
 private BehaviorChainTemplate(
     IBehaviorFactoryProvider factoryProvider,
     List <BehaviorChainItemTemplate> itemTemplates
     )
 {
     _factoryProvider = factoryProvider;
     _itemTemplates   = itemTemplates;
 }
        protected TFactory CastFactory <TFactory>(
            IBehaviorFactoryProvider factory,
            BehaviorKey behaviorToCreate
            ) where TFactory : IBehaviorFactoryProvider
        {
            if (factory is TFactory)
            {
                return((TFactory)factory);
            }

            throw new ArgumentException(
                      ExceptionTexts.WrongBehaviorFactoryType.FormatWith(
                          behaviorToCreate,
                          typeof(TFactory).Name,
                          factory.GetType().Name
                          )
                      );
        }
Beispiel #4
0
        IBehaviorFactory IBehaviorFactoryConfiguration.GetFactory(
            IBehaviorFactoryProvider factoryProvider
            )
        {
            T concreteFactoryProvider = factoryProvider as T;

            if (concreteFactoryProvider == null)
            {
                var message = ECommon
                              .WrongBehaviorFactoryProviderType
                              .FormatWith(
                    TypeService.GetFriendlyName(typeof(T)),
                    TypeService.GetFriendlyTypeName(factoryProvider)
                    );

                throw new ArgumentException(message);
            }

            return(GetFactory(concreteFactoryProvider));
        }
 public abstract IBehavior Invoke(IBehaviorFactoryProvider factory, BehaviorKey behaviorToCreate);
 public BehaviorChainTemplate(IBehaviorFactoryProvider behaviorFactory)
     : this(behaviorFactory, new List <BehaviorChainItemTemplate>())
 {
 }