/// <summary> /// Binds the specified property by using the specified controller context and binding context and the specified property descriptor. /// </summary> /// <param name="controllerContext">The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.</param> /// <param name="bindingContext">The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.</param> /// <param name="propertyDescriptor">Describes a property to be bound. The descriptor provides information such as the component type, property type, and property value. It also provides methods to get or set the property value.</param> protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor) { if (propertyDescriptor.PropertyType == typeof(AggregateReference<>) || propertyDescriptor.PropertyType == typeof(AggregateReference<>)) { var ag = new AggregateReference(); var form = controllerContext.HttpContext.Request.Form; var name = form.AllKeys.SingleOrDefault(x => x.Equals(propertyDescriptor.Name, StringComparison.InvariantCultureIgnoreCase)); if (!string.IsNullOrEmpty(name)) { var value = form.Get(name); if(value.IsValidGuid()) { ag.Guid = value; } } SetProperty(controllerContext, bindingContext, propertyDescriptor, ag.ToTypedReference()); } else { base.BindProperty(controllerContext, bindingContext, propertyDescriptor); } }
/// <summary> /// We're just putting this in as a helper method. Since we overrode the .Equals to evaluate the /// Guid we can no longer check for null instances without using the "is" operator. /// Since this is odd behavior for developers and in case we need to change it we're trying to centralize it. /// </summary> /// <param name="obj">The obj.</param> /// <returns></returns> public static AggregateReference GetAggregateReference( AggregateReference obj ) { return (obj is AggregateReference) ? obj : new AggregateReference(); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public virtual object DeepCopy( object value ) { AggregateReference result = new AggregateReference(); result.Guid = (AggregateReference) value; return result; }