[Fixes #3230] Remove use of reflection in MutableObjectModelBinder

This commit is contained in:
javiercn 2016-01-07 11:05:08 -08:00 committed by jacalvar
parent 1ca25c48af
commit 6ba05add3f
1 changed files with 3 additions and 13 deletions

View File

@ -484,14 +484,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
throw new ArgumentNullException(nameof(propertyMetadata));
}
var bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase;
var property = bindingContext.ModelType.GetProperty(propertyMetadata.PropertyName, bindingFlags);
if (property == null)
{
// Nothing to do if property does not exist.
return;
}
if (!result.IsModelSet)
{
@ -499,10 +491,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
return;
}
if (!property.CanWrite)
if (propertyMetadata.IsReadOnly)
{
// Try to handle as a collection if property exists but is not settable.
AddToProperty(bindingContext, metadata, property, result);
AddToProperty(bindingContext, metadata, propertyMetadata, result);
return;
}
@ -520,11 +512,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
private void AddToProperty(
ModelBindingContext bindingContext,
ModelMetadata modelMetadata,
PropertyInfo property,
ModelMetadata propertyMetadata,
ModelBindingResult result)
{
var propertyMetadata = modelMetadata.Properties[property.Name];
var target = propertyMetadata.PropertyGetter(bindingContext.Model);
var source = result.Model;
if (target == null || source == null)