Beispiel #1
0
 protected override HttpParameterBinding GetParameterBinding(HttpParameterDescriptor parameter)
 {
     // Use FromUri on GET and Head requests
     return(parameter.ActionDescriptor.SupportedHttpMethods.Contains(HttpMethod.Get) ||
            parameter.ActionDescriptor.SupportedHttpMethods.Contains(HttpMethod.Head) ?
            parameter.BindWithAttribute(new FromUriAttribute()) : base.GetParameterBinding(parameter));
 }
        protected override HttpParameterBinding GetParameterBinding(HttpParameterDescriptor parameter)
        {
            if (parameter.ParameterBinderAttribute == null)
            {
                var parameterType = Nullable.GetUnderlyingType(parameter.ParameterType) ?? parameter.ParameterType;
                var modelBinder   = Resolver.GetModelBinder(parameterType);

                if (modelBinder != null)
                {
                    return(parameter.BindWithModelBinding(modelBinder));
                }

                var supportedHttpMethods = parameter.ActionDescriptor.SupportedHttpMethods;
                if (supportedHttpMethods.Contains(HttpMethod.Get) || supportedHttpMethods.Contains(HttpMethod.Head))
                {
                    return(parameter.BindWithAttribute(new FromUriAttribute()));
                }
            }

            return(base.GetParameterBinding(parameter));
        }
        protected HttpParameterBinding GetParameterBinding(HttpParameterDescriptor parameter)
        {
            if (parameter.ParameterBinderAttribute != null)
            {
                return(parameter.ParameterBinderAttribute.GetBinding(parameter));
            }

            HttpParameterBinding binding = parameter.Configuration.ParameterBindingRules.LookupBinding(parameter);

            if (binding != null)
            {
                return(binding);
            }

            if (parameter.ParameterType.IsPrimitive || parameter.ParameterType == typeof(string))
            {
                return(parameter.BindWithAttribute(new ModelBinderAttribute()));
            }

            return(new FromBodyAttribute().GetBinding(parameter));
        }
        // Determine how a single parameter will get bound.
        // This is all sync. We don't need to actually read the body just to determine that we'll bind to the body.
        protected virtual HttpParameterBinding GetParameterBinding(
            HttpParameterDescriptor parameter
            )
        {
            // Attribute has the highest precedence
            // Presence of a model binder attribute overrides.
            ParameterBindingAttribute attr = parameter.ParameterBinderAttribute;

            if (attr != null)
            {
                return(attr.GetBinding(parameter));
            }

            // No attribute, so lookup in global map.
            ParameterBindingRulesCollection pb = parameter.Configuration.ParameterBindingRules;

            if (pb != null)
            {
                HttpParameterBinding binding = pb.LookupBinding(parameter);
                if (binding != null)
                {
                    return(binding);
                }
            }

            // Not explicitly specified in global map or attribute.
            // Use a default policy to determine it. These are catch-all policies.
            Type type = parameter.ParameterType;

            if (TypeHelper.CanConvertFromString(type))
            {
                // For simple types, the default is to look in URI. Exactly as if the parameter had a [FromUri] attribute.
                return(parameter.BindWithAttribute(new FromUriAttribute()));
            }

            // Fallback. Must be a complex type. Default is to look in body. Exactly as if this type had a [FromBody] attribute.
            attr = new FromBodyAttribute();
            return(attr.GetBinding(parameter));
        }
        // Determine how a single parameter will get bound. 
        // This is all sync. We don't need to actually read the body just to determine that we'll bind to the body.         
        protected virtual HttpParameterBinding GetParameterBinding(HttpParameterDescriptor parameter)
        {
            // Attribute has the highest precedence
            // Presence of a model binder attribute overrides.
            ParameterBindingAttribute attr = parameter.ParameterBinderAttribute;
            if (attr != null)
            {
                return attr.GetBinding(parameter);
            }

            // No attribute, so lookup in global map.
            ParameterBindingRulesCollection pb = parameter.Configuration.ParameterBindingRules;
            if (pb != null)
            {
                HttpParameterBinding binding = pb.LookupBinding(parameter);
                if (binding != null)
                {
                    return binding;
                }
            }

            // Not explicitly specified in global map or attribute.
            // Use a default policy to determine it. These are catch-all policies. 
            Type type = parameter.ParameterType;
            if (TypeHelper.IsSimpleUnderlyingType(type) || TypeHelper.HasStringConverter(type))
            {
                // For simple types, the default is to look in URI. Exactly as if the parameter had a [FromUri] attribute.
                return parameter.BindWithAttribute(new FromUriAttribute());
            }

            // Fallback. Must be a complex type. Default is to look in body. Exactly as if this type had a [FromBody] attribute.
            attr = new FromBodyAttribute();
            return attr.GetBinding(parameter);
        }