Xamarin Public Jenkins (auto-signing) e79aa3c0ed Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
2016-08-03 10:59:49 +00:00

32 lines
1.5 KiB
C#

namespace System.Web.ModelBinding {
public sealed class ComplexModelBinder : IModelBinder {
public bool BindModel(ModelBindingExecutionContext modelBindingExecutionContext, ModelBindingContext bindingContext) {
ModelBinderUtil.ValidateBindingContext(bindingContext, typeof(ComplexModel), false /* allowNullModel */);
ComplexModel complexModel = (ComplexModel)bindingContext.Model;
foreach (ModelMetadata propertyMetadata in complexModel.PropertyMetadata) {
ModelBindingContext propertyBindingContext = new ModelBindingContext(bindingContext) {
ModelMetadata = propertyMetadata,
ModelName = ModelBinderUtil.CreatePropertyModelName(bindingContext.ModelName, propertyMetadata.PropertyName)
};
// bind and propagate the values
IModelBinder propertyBinder = bindingContext.ModelBinderProviders.GetBinder(modelBindingExecutionContext, propertyBindingContext);
if (propertyBinder != null) {
if (propertyBinder.BindModel(modelBindingExecutionContext, propertyBindingContext)) {
complexModel.Results[propertyMetadata] = new ComplexModelResult(propertyBindingContext.Model, propertyBindingContext.ValidationNode);
}
else {
complexModel.Results[propertyMetadata] = null;
}
}
}
return true;
}
}
}