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

Commit

Permalink
Fixes issue #181 by checking to see if an own property matches some m…
Browse files Browse the repository at this point in the history
…inimum requirements before mapping
  • Loading branch information
mattbrailsford committed Jul 28, 2016
1 parent 9971d2d commit 9893605
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Expand Up @@ -118,7 +118,7 @@ public override object ProcessValue()
{
var contentProperty = contentType.GetProperty(umbracoPropertyName, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static);

if (contentProperty != null)
if (contentProperty != null && contentProperty.IsMappable())
{
// This is more than 2x as fast as propertyValue = contentProperty.GetValue(content, null);
propertyValue = PropertyInfoInvocations.GetValue(contentProperty, content);
Expand Down
Expand Up @@ -36,5 +36,27 @@ public static bool IsVirtualAndOverridable(this PropertyInfo source)
var method = source.GetGetMethod();
return method.IsVirtual && !method.IsFinal;
}

/// <summary>
/// Checks to see if a model property is mappable by Ditto
/// </summary>
/// <param name="source">
/// The source <see cref="PropertyInfo"/>.
/// </param>
/// <returns>
/// True if the <see cref="PropertyInfo"/> is mappable; otherwise, false.
/// </returns>
public static bool IsMappable(this PropertyInfo source)
{
// Make sure source is readable
if (!source.CanRead) return false;

// Check to make sure the get method has no parameters
var hasParams = source.GetIndexParameters().GetLength(0) > 0;
if (hasParams) return false;

// All checks have passed so allow it to be mapped
return true;
}
}
}

0 comments on commit 9893605

Please sign in to comment.