e79aa3c0ed
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
23 lines
1.1 KiB
C#
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;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|