Exemplo n.º 1
0
        /// <summary>
        /// Attempts to get the convention for the specified action method.
        /// </summary>
        /// <param name="method">The <see cref="MethodInfo">method</see> representing the action to retrieve the convention for.</param>
        /// <param name="convention">The retrieved <see cref="IApiVersionConvention{T}">convention</see> or <c>null</c>.</param>
        /// <returns>True if the convention was successfully retrieved; otherwise, false.</returns>
        protected override bool TryGetConvention(MethodInfo method, [NotNullWhen(true)] out IApiVersionConvention <ActionModel>?convention)
        {
            if (ActionBuilders.TryGetValue(method, out var actionBuilder) && actionBuilder != null)
            {
                return((convention = actionBuilder) != null);
            }

            convention = default;
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to get the convention for the specified action method.
        /// </summary>
        /// <param name="method">The <see cref="MethodInfo">method</see> representing the action to retrieve the convention for.</param>
        /// <param name="convention">The retrieved <see cref="IApiVersionConvention{T}">convention</see> or <c>null</c>.</param>
        /// <returns>True if the convention was successfully retrieved; otherwise, false.</returns>
        protected override bool TryGetConvention(MethodInfo method, out IApiVersionConvention <ActionModel>?convention)
        {
            if (ActionBuilders.TryGetValue(method, out var actionBuilder))
            {
                convention = actionBuilder;
                return(true);
            }

            convention = default;
            return(false);
        }
        /// <summary>
        /// Attempts to get the convention for the specified action method.
        /// </summary>
        /// <param name="method">The <see cref="MethodInfo">method</see> representing the action to retrieve the convention for.</param>
        /// <param name="convention">The retrieved <see cref="IApiVersionConvention{T}">convention</see> or <c>null</c>.</param>
        /// <returns>True if the convention was successfully retrieved; otherwise, false.</returns>
        protected override bool TryGetConvention(MethodInfo method, out IApiVersionConvention <HttpActionDescriptor>?convention)
        {
            if (ActionBuilders.TryGetValue(method, out var builder))
            {
                convention = builder;
                return(true);
            }

            convention = default;
            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Attempts to get the convention for the specified action method.
        /// </summary>
        /// <param name="method">The <see cref="MethodInfo">method</see> representing the action to retrieve the convention for.</param>
        /// <param name="convention">The retrieved <see cref="IApiVersionConvention{T}">convention</see> or <c>null</c>.</param>
        /// <returns>True if the convention was successfully retrieved; otherwise, false.</returns>
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
        protected override bool TryGetConvention(MethodInfo method, out IApiVersionConvention <ActionModel>?convention)
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
        {
            if (ActionBuilders.TryGetValue(method, out var actionBuilder))
            {
                convention = actionBuilder;
                return(true);
            }

            convention = default;
            return(false);
        }
        /// <summary>
        /// Attempts to get the convention for the specified action method.
        /// </summary>
        /// <param name="method">The <see cref="MethodInfo">method</see> representing the action to retrieve the convention for.</param>
        /// <param name="convention">The retrieved <see cref="IApiVersionConvention{T}">convention</see> or <c>null</c>.</param>
        /// <returns>True if the convention was successfully retrieved; otherwise, false.</returns>
        protected override bool TryGetConvention(MethodInfo method, out IApiVersionConvention <HttpActionDescriptor> convention)
        {
            Arg.NotNull(method, nameof(method));

            if (ActionBuilders.TryGetValue(method, out var builder))
            {
                convention = builder;
                return(true);
            }

            convention = default(IApiVersionConvention <HttpActionDescriptor>);
            return(false);
        }
        void ApplyActionConventions(HttpControllerDescriptor controllerDescriptor)
        {
            Contract.Requires(controllerDescriptor != null);

            var actionSelector    = controllerDescriptor.Configuration.Services.GetActionSelector();
            var actionDescriptors = actionSelector.GetActionMapping(controllerDescriptor).SelectMany(g => g.OfType <ReflectedHttpActionDescriptor>());

            foreach (var actionDescriptor in actionDescriptors)
            {
                var key = actionDescriptor.MethodInfo;

                if (ActionBuilders.TryGetValue(key, out var actionBuilder))
                {
                    actionBuilder.ApplyTo(actionDescriptor);
                }
            }
        }
Exemplo n.º 7
0
 public BuilderFactories(IStatFactory statFactory, IReadOnlyList <SkillDefinition> skills)
 {
     ActionBuilders     = new ActionBuilders(statFactory);
     BuffBuilders       = new BuffBuilders(statFactory, skills);
     ChargeTypeBuilders = new ChargeTypeBuilders(statFactory);
     ConditionBuilders  = new ConditionBuilders(statFactory);
     DamageTypeBuilders = new DamageTypeBuilders(statFactory);
     EffectBuilders     = new EffectBuilders(statFactory);
     EntityBuilders     = new EntityBuilders(statFactory);
     EquipmentBuilders  = new EquipmentBuilders(statFactory);
     FormBuilders       = new FormBuilders();
     KeywordBuilders    = new KeywordBuilders();
     SkillBuilders      = new SkillBuilders(statFactory, skills);
     StatBuilders       = new StatBuilders(statFactory);
     ValueBuilders      = new ValueBuilders();
     ItemSlotBuilders   = new ItemSlotBuilders();
 }
Exemplo n.º 8
0
        public BuilderFactories(SkillDefinitions skills)
        {
            var statFactory = new StatFactory();

            ActionBuilders     = new ActionBuilders(statFactory);
            BuffBuilders       = new BuffBuilders(statFactory, skills);
            ChargeTypeBuilders = new ChargeTypeBuilders(statFactory);
            ConditionBuilders  = new ConditionBuilders(statFactory);
            DamageTypeBuilders = new DamageTypeBuilders(statFactory);
            EffectBuilders     = new EffectBuilders(statFactory);
            EntityBuilders     = new EntityBuilders(statFactory);
            EquipmentBuilders  = new EquipmentBuilders(statFactory);
            FormBuilders       = new FormBuilders();
            KeywordBuilders    = new KeywordBuilders();
            SkillBuilders      = new SkillBuilders(statFactory, skills);
            StatBuilders       = new StatBuilders(statFactory);
            ValueBuilders      = new ValueBuilders();
            MetaStatBuilders   = new MetaStatBuilders(statFactory);
            MatchContexts      = new MatchContexts(statFactory);
        }
        private void ApplyActionConventions(ControllerModel controller, ControllerVersionInfo controllerVersionInfo)
        {
            Contract.Requires(controller != null);

            foreach (var action in controller.Actions)
            {
                var key           = action.ActionMethod;
                var actionBuilder = default(ActionApiVersionConventionBuilder <T>);

                action.SetProperty(controller);

                if (ActionBuilders.TryGetValue(key, out actionBuilder))
                {
                    action.SetProperty(controllerVersionInfo);
                    actionBuilder.ApplyTo(action);
                    action.SetProperty(default(ControllerVersionInfo));
                }
                else
                {
                    action.SetProperty(new ApiVersionModel(controller, action));
                }
            }
        }
        void MergeActionAttributesWithConventions(ControllerModel controller, ControllerVersionInfo controllerVersionInfo)
        {
            Contract.Requires(controller != null);
            Contract.Requires(controllerVersionInfo != null);

            foreach (var action in controller.Actions)
            {
                var key = action.ActionMethod;

                action.SetProperty(controller);

                if (ActionBuilders.TryGetValue(key, out var actionBuilder))
                {
                    action.SetProperty(controllerVersionInfo);
                    actionBuilder.ApplyTo(action);
                    action.SetProperty(default(ControllerVersionInfo));
                }
                else
                {
                    action.SetProperty(new ApiVersionModel(controller, action));
                }
            }
        }