diff --git a/src/Microsoft.AspNet.Mvc.Common/Microsoft.AspNet.Mvc.Common.kproj b/src/Microsoft.AspNet.Mvc.Common/Microsoft.AspNet.Mvc.Common.kproj
index 87d0bfd666..a82a179555 100644
--- a/src/Microsoft.AspNet.Mvc.Common/Microsoft.AspNet.Mvc.Common.kproj
+++ b/src/Microsoft.AspNet.Mvc.Common/Microsoft.AspNet.Mvc.Common.kproj
@@ -22,7 +22,8 @@
+
-
+
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Mvc.Core/Internal/PropertyHelper.cs b/src/Microsoft.AspNet.Mvc.Common/PropertyHelper.cs
similarity index 91%
rename from src/Microsoft.AspNet.Mvc.Core/Internal/PropertyHelper.cs
rename to src/Microsoft.AspNet.Mvc.Common/PropertyHelper.cs
index 893f54cbef..666ec7a3c2 100644
--- a/src/Microsoft.AspNet.Mvc.Core/Internal/PropertyHelper.cs
+++ b/src/Microsoft.AspNet.Mvc.Common/PropertyHelper.cs
@@ -33,14 +33,15 @@ namespace Microsoft.AspNet.Mvc
///
/// This constructor does not cache the helper. For caching, use GetProperties.
///
- public PropertyHelper(PropertyInfo property)
+ public PropertyHelper([NotNull] PropertyInfo property)
{
- Contract.Assert(property != null);
-
+ Property = property;
Name = property.Name;
_valueGetter = MakeFastPropertyGetter(property);
}
+ public PropertyInfo Property { get; private set; }
+
public virtual string Name { get; protected set; }
public object GetValue(object instance)
@@ -57,7 +58,19 @@ namespace Microsoft.AspNet.Mvc
///
public static PropertyHelper[] GetProperties(object instance)
{
- return GetProperties(instance, CreateInstance, ReflectionCache);
+ return GetProperties(instance.GetType());
+ }
+
+ ///
+ /// Creates and caches fast property helpers that expose getters for every public get property on the
+ /// specified type.
+ ///
+ /// the type to extract property accessors for.
+ /// a cached array of all public property getters from the type of target instance.
+ ///
+ public static PropertyHelper[] GetProperties(Type type)
+ {
+ return GetProperties(type, CreateInstance, ReflectionCache);
}
///
@@ -181,19 +194,17 @@ namespace Microsoft.AspNet.Mvc
}
protected static PropertyHelper[] GetProperties(
- object instance,
+ Type type,
Func createPropertyHelper,
ConcurrentDictionary cache)
{
// Using an array rather than IEnumerable, as target will be called on the hot path numerous times.
PropertyHelper[] helpers;
- var type = instance.GetType();
-
if (!cache.TryGetValue(type, out helpers))
{
// We avoid loading indexed properties using the where statement.
- // Indexed properties are not useful (or valid) for grabbing properties off an anonymous object.
+ // Indexed properties are not useful (or valid) for grabbing properties off an object.
var properties = type.GetRuntimeProperties().Where(
prop => prop.GetIndexParameters().Length == 0 &&
prop.GetMethod != null &&
diff --git a/src/Microsoft.AspNet.Mvc.Common/project.json b/src/Microsoft.AspNet.Mvc.Common/project.json
index ad5b80a7e1..90bfb2c484 100644
--- a/src/Microsoft.AspNet.Mvc.Common/project.json
+++ b/src/Microsoft.AspNet.Mvc.Common/project.json
@@ -4,6 +4,7 @@
"dependencies": {
"System.Linq": "4.0.0.0",
"System.Reflection": "4.0.10.0",
+ "System.Reflection.Extensions": "4.0.0.0",
"System.Runtime" : "4.0.20.0"
},
"configurations": {
diff --git a/src/Microsoft.AspNet.Mvc.Core/Microsoft.AspNet.Mvc.Core.kproj b/src/Microsoft.AspNet.Mvc.Core/Microsoft.AspNet.Mvc.Core.kproj
index 0291a37558..fbaec86171 100644
--- a/src/Microsoft.AspNet.Mvc.Core/Microsoft.AspNet.Mvc.Core.kproj
+++ b/src/Microsoft.AspNet.Mvc.Core/Microsoft.AspNet.Mvc.Core.kproj
@@ -136,7 +136,6 @@
-
diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlAttributePropertyHelper.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlAttributePropertyHelper.cs
index 08db8b6c18..bae504aa50 100644
--- a/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlAttributePropertyHelper.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlAttributePropertyHelper.cs
@@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
public static new PropertyHelper[] GetProperties(object instance)
{
- return GetProperties(instance, CreateInstance, ReflectionCache);
+ return GetProperties(instance.GetType(), CreateInstance, ReflectionCache);
}
private static PropertyHelper CreateInstance(PropertyInfo property)
diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/AssociatedMetadataProvider.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/AssociatedMetadataProvider.cs
index e2c5e2d4da..2e23e34724 100644
--- a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/AssociatedMetadataProvider.cs
+++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/AssociatedMetadataProvider.cs
@@ -4,10 +4,8 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
-using System.Diagnostics.Contracts;
using System.Linq;
using System.Reflection;
-using System.Reflection.Emit;
namespace Microsoft.AspNet.Mvc.ModelBinding
{
@@ -67,8 +65,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
Func