/// <summary> /// Binds the specified controller action parameter. /// </summary> /// <param name="controllerActionParameter">The controller action parameter.</param> /// <param name="controllerActionRoute">The controller action route.</param> public static void Bind(IControllerActionParameter controllerActionParameter, IControllerActionRoute controllerActionRoute) { foreach (var binder in _binders.Where(x => x.CanBind(controllerActionParameter))) { binder.Bind(controllerActionParameter, controllerActionRoute); } }
/// <summary> /// Binds the parameter to a route /// </summary> /// <param name="parameter">The parameter.</param> /// <param name="controllerActionRoute">The controller action route.</param> public void Bind(IControllerActionParameter parameter, IControllerActionRoute controllerActionRoute) { //ignore parameters with null values. if (parameter.ParameterValue == null) { return; } BindParameter(parameter, controllerActionRoute); }
protected override void BindParameter(IControllerActionParameter parameter, IControllerActionRoute controllerActionRoute) { var complexModel = parameter.ParameterValue as ComplexModel; if (complexModel.Id == null) { throw new System.ArgumentException("complexModel.Id can not be null. Did you forget to set it on your source model?"); } controllerActionRoute.SetRouteValue("myid", complexModel.Id); }
/// <summary> /// Binds the parameter to a route. /// </summary> /// <param name="parameter">The parameter.</param> /// <param name="controllerActionRoute">The controller action route.</param> protected override void BindParameter(IControllerActionParameter parameter, IControllerActionRoute controllerActionRoute) { if (parameter.ParameterValue is string || parameter.ParameterValue.GetType().IsPrimitive) { controllerActionRoute.SetQueryStringParameter(parameter.ParameterName, parameter.ParameterValue.ToString()); } else { //assume we need to pass the model as a query string parameter var properties = from p in parameter.ParameterValue.GetType().GetProperties() where p.GetValue(parameter.ParameterValue, null) != null select new { Name = p.Name, Val = HttpUtility.UrlEncode(p.GetValue(parameter.ParameterValue, null).ToString()) }; foreach (var property in properties) { controllerActionRoute.SetQueryStringParameter(property.Name, property.Val); } } }
/// <summary> /// Determines whether BindingSourceMetadata is of the specified type. /// </summary> /// <typeparam name="TAttributeType">The type of the attribute type.</typeparam> /// <param name="paramter">The paramter.</param> /// <returns> /// <c>true</c> if [is binding source of type] [the specified paramter]; otherwise, <c>false</c>. /// </returns> protected bool IsBindingSourceOfType <TAttributeType>(IControllerActionParameter paramter) { return(paramter.BindingSourceMetadata?.GetType().Equals(typeof(TAttributeType)) ?? false); }
/// <summary> /// Binds the parameter to a route. /// </summary> /// <param name="parameter">The parameter.</param> /// <param name="controllerActionRoute">The controller action route.</param> protected abstract void BindParameter(IControllerActionParameter parameter, IControllerActionRoute controllerActionRoute);
/// <summary> /// Determines whether this instance can bind the specified parameter. /// </summary> /// <param name="parameter">The parameter.</param> /// <returns> /// <c>true</c> if this instance can decompose the specified parameter; otherwise, <c>false</c>. /// </returns> public abstract bool CanBind(IControllerActionParameter parameter);
/// <summary> /// Determines whether this instance can bind the specified parameter. /// </summary> /// <param name="parameter">The parameter.</param> /// <returns> /// <c>true</c> if this instance can decompose the specified parameter; otherwise, <c>false</c>. /// </returns> public override bool CanBind(IControllerActionParameter parameter) { return(IsBindingSourceOfType <FromBodyAttribute>(parameter)); }
/// <summary> /// Binds the parameter to a route. /// </summary> /// <param name="parameter">The parameter.</param> /// <param name="controllerActionRoute">The controller action route.</param> protected override void BindParameter(IControllerActionParameter parameter, IControllerActionRoute controllerActionRoute) { controllerActionRoute.SetModel(parameter.ParameterValue); }
/// <summary> /// Determines whether this instance can bind the specified parameter. /// </summary> /// <param name="parameter">The parameter.</param> /// <returns> /// <c>true</c> if this instance can bind the specified parameter; otherwise, <c>false</c>. /// </returns> public override bool CanBind(IControllerActionParameter parameter) { return(parameter.BindingSourceMetadata == null); }
/// <summary> /// Binds the parameter to a route. /// </summary> /// <param name="parameter">The parameter.</param> /// <param name="controllerActionRoute">The controller action route.</param> protected override void BindParameter(IControllerActionParameter parameter, IControllerActionRoute controllerActionRoute) { }
public override bool CanBind(IControllerActionParameter parameter) { return(parameter.ParameterValue is ComplexModel); }