Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
[Fixes #3230] Remove use of reflection in MutableObjectModelBinder
Browse files Browse the repository at this point in the history
  • Loading branch information
javiercn committed Jan 12, 2016
1 parent 1ca25c4 commit 6ba05ad
Showing 1 changed file with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -484,25 +484,17 @@ protected virtual void SetProperty(
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)
{
// If we don't have a value, don't set it on the model and trounce a pre-initialized value.
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;
}

Expand All @@ -520,11 +512,9 @@ protected virtual void SetProperty(
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)
Expand Down

0 comments on commit 6ba05ad

Please sign in to comment.