Ejemplo n.º 1
0
        /// <summary>
        /// Bind the incoming request to an existing instance and validate
        /// </summary>
        /// <typeparam name="TModel">Model type</typeparam>
        /// <param name="module">Current module</param>
        /// <param name="instance">The class instance to bind properties to</param>
        /// <param name="configuration">The <see cref="BindingConfig"/> that should be applied during binding.</param>
        /// <param name="blacklistedProperties">Property names to blacklist from binding</param>
        /// <remarks><see cref="ModelValidationResult"/> is stored in NancyModule.ModelValidationResult and NancyContext.ModelValidationResult.</remarks>
        public static TModel BindToAndValidate <TModel>(this INancyModule module, TModel instance, BindingConfig configuration, params string[] blacklistedProperties)
        {
            var model = module.BindTo <TModel>(instance, configuration, blacklistedProperties);

            module.Validate(model);
            return(model);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Bind the incoming request to a model and validate
        /// </summary>
        /// <typeparam name="TModel">Model type</typeparam>
        /// <param name="module">Current module</param>
        /// <param name="blacklistedProperties">Property names to blacklist from binding</param>
        /// <returns>Bound model instance</returns>
        /// <remarks><see cref="ModelValidationResult"/> is stored in NancyModule.ModelValidationResult and NancyContext.ModelValidationResult.</remarks>
        public static TModel BindAndValidate <TModel>(this INancyModule module, params string[] blacklistedProperties)
        {
            var model = module.Bind <TModel>(blacklistedProperties);

            module.Validate(model);
            return(model);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Bind the incoming request to an existing instance and validate
        /// </summary>
        /// <typeparam name="TModel">Model type</typeparam>
        /// <param name="module">Current module</param>
        /// <param name="instance">The class instance to bind properties to</param>
        /// <param name="blacklistedProperties">Expressions that tell which property should be ignored</param>
        /// <example>this.Bind&lt;Person&gt;(p =&gt; p.Name, p =&gt; p.Age)</example>
        /// <remarks><see cref="ModelValidationResult"/> is stored in NancyModule.ModelValidationResult and NancyContext.ModelValidationResult.</remarks>
        public static TModel BindToAndValidate <TModel>(this INancyModule module, TModel instance, params Expression <Func <TModel, object> >[] blacklistedProperties)
        {
            var model = module.BindTo <TModel>(instance, blacklistedProperties.ParseBlacklistedPropertiesExpressionTree());

            module.Validate(model);
            return(model);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Bind the incoming request to a model and validate
        /// </summary>
        /// <typeparam name="TModel">Model type</typeparam>
        /// <param name="module">Current module</param>
        /// <param name="configuration">The <see cref="BindingConfig"/> that should be applied during binding.</param>
        /// <param name="blacklistedProperties">Expressions that tell which property should be ignored</param>
        /// <example>this.Bind&lt;Person&gt;(p =&gt; p.Name, p =&gt; p.Age)</example>
        /// <returns>Bound model instance</returns>
        /// <remarks><see cref="ModelValidationResult"/> is stored in NancyModule.ModelValidationResult and NancyContext.ModelValidationResult.</remarks>
        public static TModel BindAndValidate <TModel>(this INancyModule module, BindingConfig configuration, params Expression <Func <TModel, object> >[] blacklistedProperties)
        {
            var model = module.Bind <TModel>(configuration, blacklistedProperties.ParseBlacklistedPropertiesExpressionTree());

            module.Validate(model);
            return(model);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Bind the incoming request to an existing instance and validate
        /// </summary>
        /// <typeparam name="TModel">Model type</typeparam>
        /// <param name="module">Current module</param>
        /// <param name="instance">The class instance to bind properties to</param>
        /// <remarks><see cref="ModelValidationResult"/> is stored in NancyModule.ModelValidationResult and NancyContext.ModelValidationResult.</remarks>
        public static TModel BindToAndValidate <TModel>(this INancyModule module, TModel instance)
        {
            var model = module.BindTo(instance, NoBlacklistedProperties);

            module.Validate(model);
            return(model);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Bind the incoming request to a model and validate
        /// </summary>
        /// <typeparam name="TModel">Model type</typeparam>
        /// <param name="module">Current module</param>
        /// <param name="configuration">The <see cref="BindingConfig"/> that should be applied during binding.</param>
        /// <returns>Bound model instance</returns>
        /// <remarks><see cref="ModelValidationResult"/> is stored in NancyModule.ModelValidationResult and NancyContext.ModelValidationResult.</remarks>
        public static TModel BindAndValidate <TModel>(this INancyModule module, BindingConfig configuration)
        {
            var model = module.Bind <TModel>(configuration, NoBlacklistedProperties);

            module.Validate(model);
            return(model);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Bind the incoming request to a model and validate
        /// </summary>
        /// <typeparam name="TModel">Model type</typeparam>
        /// <param name="module">Current module</param>
        /// <returns>Bound model instance</returns>
        /// <remarks><see cref="ModelValidationResult"/> is stored in NancyModule.ModelValidationResult and NancyContext.ModelValidationResult.</remarks>
        public static TModel BindAndValidate <TModel>(this INancyModule module)
        {
            var model = module.Bind <TModel>(NoBlacklistedProperties);

            module.Validate(model);
            return(model);
        }