Modify GetProperties overload (#6276)

Addresses https://github.com/aspnet/Common/issues/219
This commit is contained in:
Jass Bagga 2017-05-16 13:34:14 -07:00 committed by GitHub
parent 4d905a4110
commit 51c142ae91
3 changed files with 8 additions and 7 deletions

View File

@ -13,9 +13,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
private static readonly ConcurrentDictionary<Type, PropertyHelper[]> ReflectionCache =
new ConcurrentDictionary<Type, PropertyHelper[]>();
public static new PropertyHelper[] GetProperties(object instance)
public static new PropertyHelper[] GetProperties(Type type)
{
return GetProperties(instance.GetType(), CreateInstance, ReflectionCache);
return GetProperties(type, CreateInstance, ReflectionCache);
}
private static PropertyHelper CreateInstance(PropertyInfo property)

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
@ -203,7 +204,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
if (htmlAttributes != null)
{
foreach (var helper in HtmlAttributePropertyHelper.GetProperties(htmlAttributes))
foreach (var helper in HtmlAttributePropertyHelper.GetProperties(htmlAttributes.GetType()))
{
dictionary[helper.Name] = helper.GetValue(htmlAttributes);
}

View File

@ -77,8 +77,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
var anonymous = new { foo = "bar" };
// Act
var helpers1 = HtmlAttributePropertyHelper.GetProperties(anonymous);
var helpers2 = HtmlAttributePropertyHelper.GetProperties(anonymous);
var helpers1 = HtmlAttributePropertyHelper.GetProperties(anonymous.GetType());
var helpers2 = HtmlAttributePropertyHelper.GetProperties(anonymous.GetType());
// Assert
Assert.Equal(1, helpers1.Length);
@ -93,8 +93,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
var anonymous = new { bar_baz1 = "foo" };
// Act
var helpers1 = HtmlAttributePropertyHelper.GetProperties(anonymous);
var helpers2 = PropertyHelper.GetProperties(anonymous);
var helpers1 = HtmlAttributePropertyHelper.GetProperties(anonymous.GetType());
var helpers2 = PropertyHelper.GetProperties(anonymous.GetType());
// Assert
Assert.Equal(1, helpers1.Length);