diff --git a/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperDescriptorFactory.cs b/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperDescriptorFactory.cs
index eef0babed5..b898cb0219 100644
--- a/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperDescriptorFactory.cs
+++ b/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperDescriptorFactory.cs
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
+using System.Text.RegularExpressions;
using Microsoft.AspNet.Razor.TagHelpers;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
@@ -15,6 +16,14 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
public static class TagHelperDescriptorFactory
{
private const string TagHelperNameEnding = "TagHelper";
+ private const string HtmlCaseRegexReplacement = "-$1$2";
+
+ // This matches the following AFTER the start of the input string (MATCH).
+ // Any letter/number followed by an uppercase letter then lowercase letter: 1(Aa), a(Aa), A(Aa)
+ // Any lowercase letter followed by an uppercase letter: a(A)
+ // Each match is then prefixed by a "-" via the ToHtmlCase method.
+ private static readonly Regex HtmlCaseRegex =
+ new Regex("(?(inherit: false);
var attributeName = attributeNameAttribute != null ?
attributeNameAttribute.Name :
- property.Name;
+ ToHtmlCase(property.Name);
return new TagHelperAttributeDescriptor(attributeName, property.Name, property.PropertyType.FullName);
}
@@ -97,5 +106,22 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
property.SetMethod != null &&
property.SetMethod.IsPublic;
}
+
+ ///
+ /// Converts from pascal/camel case to lower kebab-case.
+ ///
+ ///
+ /// SomeThing => some-thing
+ /// capsONInside => caps-on-inside
+ /// CAPSOnOUTSIDE => caps-on-outside
+ /// ALLCAPS => allcaps
+ /// One1Two2Three3 => one1-two2-three3
+ /// ONE1TWO2THREE3 => one1two2three3
+ /// First_Second_ThirdHi => first_second_third-hi
+ ///
+ private static string ToHtmlCase(string name)
+ {
+ return HtmlCaseRegex.Replace(name, HtmlCaseRegexReplacement).ToLowerInvariant();
+ }
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Razor.Runtime/project.json b/src/Microsoft.AspNet.Razor.Runtime/project.json
index f23e454816..3728d59c00 100644
--- a/src/Microsoft.AspNet.Razor.Runtime/project.json
+++ b/src/Microsoft.AspNet.Razor.Runtime/project.json
@@ -9,7 +9,8 @@
"aspnet50": { },
"aspnetcore50": {
"dependencies": {
- "System.Reflection.Extensions": "4.0.0-beta-*"
+ "System.Reflection.Extensions": "4.0.0-beta-*",
+ "System.Text.RegularExpressions": "4.0.10-beta-*"
}
}
}