From 829faaaa4b2e6ad710c1ccc74f0ee4e6d74dd4a7 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 30 Oct 2014 14:36:16 -0700 Subject: [PATCH] Change TagHelperAttributeDescriptor to not depend on PropertyInfo. - Right now the only information that is used from the PropertyInfo is the PropertyName and the PropertyType, therefore changed the PropertyInfo property on TagHelperAttributeDescriptor to be AttributeTypeName since we already had an accessor for AttributePropertyName. - Modified test comparers to validate type names. #214 --- .../CSharp/CSharpTagHelperCodeRenderer.cs | 2 +- .../TagHelperAttributeDescriptor.cs | 32 ++++++++++++------- .../CompleteTagHelperDescriptorComparer.cs | 4 ++- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpTagHelperCodeRenderer.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpTagHelperCodeRenderer.cs index 3eff0ea711..d1c276caac 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpTagHelperCodeRenderer.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpTagHelperCodeRenderer.cs @@ -497,7 +497,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp private static bool IsStringAttribute(TagHelperAttributeDescriptor attributeDescriptor) { - return attributeDescriptor.PropertyInfo.PropertyType == typeof(string); + return attributeDescriptor.AttributeTypeName == typeof(string).FullName; } private static bool TryGetPlainTextValue(Chunk chunk, out string plainText) diff --git a/src/Microsoft.AspNet.Razor/TagHelpers/TagHelperAttributeDescriptor.cs b/src/Microsoft.AspNet.Razor/TagHelpers/TagHelperAttributeDescriptor.cs index 17529bc8ae..528dfeb611 100644 --- a/src/Microsoft.AspNet.Razor/TagHelpers/TagHelperAttributeDescriptor.cs +++ b/src/Microsoft.AspNet.Razor/TagHelpers/TagHelperAttributeDescriptor.cs @@ -16,11 +16,27 @@ namespace Microsoft.AspNet.Razor.TagHelpers /// The HTML attribute name. /// The for the tag /// helper attribute + public TagHelperAttributeDescriptor(string attributeName, PropertyInfo propertyInfo) + : this(attributeName, propertyInfo.Name, propertyInfo.PropertyType.FullName) + { + } + + /// + /// Instantiates a new class. + /// + /// The HTML attribute name. + /// The name of the CLR property name that corresponds to the HTML + /// attribute name. + /// + /// The full name of the that corresponds to the HTML attribute. + /// public TagHelperAttributeDescriptor(string attributeName, - PropertyInfo propertyInfo) + string attributePropertyName, + string attributeTypeName) { AttributeName = attributeName; - PropertyInfo = propertyInfo; + AttributePropertyName = attributePropertyName; + AttributeTypeName = attributeTypeName; } /// @@ -31,17 +47,11 @@ namespace Microsoft.AspNet.Razor.TagHelpers /// /// The name of the CLR property name that corresponds to the HTML attribute name. /// - public string AttributePropertyName - { - get - { - return PropertyInfo.Name; - } - } + public string AttributePropertyName { get; private set; } /// - /// The for the tag helper attribute + /// The full name of the that corresponds to the HTML attribute. /// - public PropertyInfo PropertyInfo { get; private set; } + public string AttributeTypeName { get; private set; } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/CompleteTagHelperDescriptorComparer.cs b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/CompleteTagHelperDescriptorComparer.cs index cae296645c..2177d96646 100644 --- a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/CompleteTagHelperDescriptorComparer.cs +++ b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/CompleteTagHelperDescriptorComparer.cs @@ -44,7 +44,8 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers public bool Equals(TagHelperAttributeDescriptor descriptorX, TagHelperAttributeDescriptor descriptorY) { return descriptorX.AttributeName == descriptorY.AttributeName && - descriptorX.AttributePropertyName == descriptorY.AttributePropertyName; + descriptorX.AttributePropertyName == descriptorY.AttributePropertyName && + descriptorX.AttributeTypeName == descriptorY.AttributeTypeName; } public int GetHashCode(TagHelperAttributeDescriptor descriptor) @@ -52,6 +53,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers return HashCodeCombiner.Start() .Add(descriptor.AttributeName) .Add(descriptor.AttributePropertyName) + .Add(descriptor.AttributeTypeName) .CombinedHash; } }