Modify GetProperties overload (#6276)
Addresses https://github.com/aspnet/Common/issues/219
This commit is contained in:
parent
4d905a4110
commit
51c142ae91
|
|
@ -13,9 +13,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
||||||
private static readonly ConcurrentDictionary<Type, PropertyHelper[]> ReflectionCache =
|
private static readonly ConcurrentDictionary<Type, PropertyHelper[]> ReflectionCache =
|
||||||
new ConcurrentDictionary<Type, PropertyHelper[]>();
|
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)
|
private static PropertyHelper CreateInstance(PropertyInfo property)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -203,7 +204,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
|
|
||||||
if (htmlAttributes != null)
|
if (htmlAttributes != null)
|
||||||
{
|
{
|
||||||
foreach (var helper in HtmlAttributePropertyHelper.GetProperties(htmlAttributes))
|
foreach (var helper in HtmlAttributePropertyHelper.GetProperties(htmlAttributes.GetType()))
|
||||||
{
|
{
|
||||||
dictionary[helper.Name] = helper.GetValue(htmlAttributes);
|
dictionary[helper.Name] = helper.GetValue(htmlAttributes);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
||||||
var anonymous = new { foo = "bar" };
|
var anonymous = new { foo = "bar" };
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var helpers1 = HtmlAttributePropertyHelper.GetProperties(anonymous);
|
var helpers1 = HtmlAttributePropertyHelper.GetProperties(anonymous.GetType());
|
||||||
var helpers2 = HtmlAttributePropertyHelper.GetProperties(anonymous);
|
var helpers2 = HtmlAttributePropertyHelper.GetProperties(anonymous.GetType());
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(1, helpers1.Length);
|
Assert.Equal(1, helpers1.Length);
|
||||||
|
|
@ -93,8 +93,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
||||||
var anonymous = new { bar_baz1 = "foo" };
|
var anonymous = new { bar_baz1 = "foo" };
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var helpers1 = HtmlAttributePropertyHelper.GetProperties(anonymous);
|
var helpers1 = HtmlAttributePropertyHelper.GetProperties(anonymous.GetType());
|
||||||
var helpers2 = PropertyHelper.GetProperties(anonymous);
|
var helpers2 = PropertyHelper.GetProperties(anonymous.GetType());
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(1, helpers1.Length);
|
Assert.Equal(1, helpers1.Length);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue