From 51c142ae915008679c77db47d5ef33a04ceef23f Mon Sep 17 00:00:00 2001 From: Jass Bagga Date: Tue, 16 May 2017 13:34:14 -0700 Subject: [PATCH] Modify GetProperties overload (#6276) Addresses https://github.com/aspnet/Common/issues/219 --- .../Internal/HtmlAttributePropertyHelper.cs | 4 ++-- .../ViewFeatures/HtmlHelper.cs | 3 ++- .../Internal/HtmlAttributePropertyHelperTest.cs | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/HtmlAttributePropertyHelper.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/HtmlAttributePropertyHelper.cs index 98a425b3ae..6fd48b6ea4 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/HtmlAttributePropertyHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/HtmlAttributePropertyHelper.cs @@ -13,9 +13,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal private static readonly ConcurrentDictionary ReflectionCache = new ConcurrentDictionary(); - 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) diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs index 008719ec2f..d4dfc63420 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs @@ -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); } diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/HtmlAttributePropertyHelperTest.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/HtmlAttributePropertyHelperTest.cs index c9b2c02be0..12bfae0bbc 100644 --- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/HtmlAttributePropertyHelperTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/HtmlAttributePropertyHelperTest.cs @@ -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);