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

23 lines
1.1 KiB
C#

namespace System.Web.ModelBinding {
using System.Collections.Generic;
public sealed class KeyValuePairModelBinderProvider : ModelBinderProvider {
public override IModelBinder GetBinder(ModelBindingExecutionContext modelBindingExecutionContext, ModelBindingContext bindingContext) {
ModelBinderUtil.ValidateBindingContext(bindingContext);
string keyFieldName = ModelBinderUtil.CreatePropertyModelName(bindingContext.ModelName, "key");
string valueFieldName = ModelBinderUtil.CreatePropertyModelName(bindingContext.ModelName, "value");
if (bindingContext.UnvalidatedValueProvider.ContainsPrefix(keyFieldName) && bindingContext.UnvalidatedValueProvider.ContainsPrefix(valueFieldName)) {
return ModelBinderUtil.GetPossibleBinderInstance(bindingContext.ModelType, typeof(KeyValuePair<,>) /* supported model type */, typeof(KeyValuePairModelBinder<,>) /* binder type */);
}
else {
// 'key' or 'value' missing
return null;
}
}
}
}