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

Commit

Permalink
Fix #2986 - Make ModelMetadata getters null-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
rynowak committed Aug 19, 2015
1 parent 485e6e5 commit 91147d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Expand Up @@ -122,7 +122,8 @@ protected virtual DefaultMetadataDetails[] CreatePropertyDetails([NotNull] Model
var propertyEntry = new DefaultMetadataDetails(propertyKey, attributes);
if (propertyHelper.Property.CanRead && propertyHelper.Property.GetMethod?.IsPublic == true)
{
propertyEntry.PropertyGetter = propertyHelper.ValueGetter;
var getter = PropertyHelper.MakeNullSafeFastPropertyGetter(propertyHelper.Property);
propertyEntry.PropertyGetter = getter;
}

if (propertyHelper.Property.CanWrite &&
Expand Down
Expand Up @@ -287,10 +287,7 @@ private static bool CanUpdateReadOnlyProperty(Type propertyType)
// instances or overwrite inner properties that are not bound. No need for this with simple values
// because they will be overwritten if binding succeeds. Arrays are never reused because they cannot
// be resized.
//
// ModelMetadata.PropertyGetter is not null safe; use it only if Model is non-null.
if (bindingContext.Model != null &&
propertyMetadata.PropertyGetter != null &&
if (propertyMetadata.PropertyGetter != null &&
propertyMetadata.IsComplexType &&
!propertyMetadata.ModelType.IsArray)
{
Expand Down

0 comments on commit 91147d4

Please sign in to comment.