From 04d7e63b79e9e75aa175547e8d3c5441f4a98a3c Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Sun, 30 Jun 2019 15:28:46 -0700 Subject: [PATCH] Add culture parameter to element-bind tag helpers \n\nCommit migrated from https://github.com/dotnet/aspnetcore-tooling/commit/7515e2ce49c3c629b38c4393f3f6fb7e5992add3 --- .../src/ComponentResources.resx | 3 ++ .../src/BindTagHelperDescriptorProvider.cs | 19 ++++++++ .../BindTagHelperDescriptorProviderTest.cs | 45 ++++++++++++++++++- 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/ComponentResources.resx b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/ComponentResources.resx index f932064455..610c13afcf 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/ComponentResources.resx +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/ComponentResources.resx @@ -129,6 +129,9 @@ Binds the provided expression to the '{0}' property and a change event delegate to the '{1}' property of the component. + + Specifies the culture to use for conversions. + Binds the provided expression to the '{0}' attribute and a change event delegate to the '{1}' attribute. diff --git a/src/Razor/Microsoft.CodeAnalysis.Razor/src/BindTagHelperDescriptorProvider.cs b/src/Razor/Microsoft.CodeAnalysis.Razor/src/BindTagHelperDescriptorProvider.cs index 8ad405c6b5..8b1ba0a7a9 100644 --- a/src/Razor/Microsoft.CodeAnalysis.Razor/src/BindTagHelperDescriptorProvider.cs +++ b/src/Razor/Microsoft.CodeAnalysis.Razor/src/BindTagHelperDescriptorProvider.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Components; @@ -177,6 +178,15 @@ namespace Microsoft.CodeAnalysis.Razor parameter.SetPropertyName("Event"); }); + + attribute.BindAttributeParameter(parameter => + { + parameter.Name = "culture"; + parameter.TypeName = typeof(CultureInfo).FullName; + parameter.Documentation = ComponentResources.BindTagHelper_Element_Culture_Documentation; + + parameter.SetPropertyName("Culture"); + }); }); // This is no longer supported. This is just here so we can add a diagnostic later on when this matches. @@ -381,6 +391,15 @@ namespace Microsoft.CodeAnalysis.Razor parameter.SetPropertyName(eventName); }); + + a.BindAttributeParameter(parameter => + { + parameter.Name = "culture"; + parameter.TypeName = typeof(CultureInfo).FullName; + parameter.Documentation = ComponentResources.BindTagHelper_Element_Culture_Documentation; + + parameter.SetPropertyName("Culture"); + }); }); // This is no longer supported. This is just here so we can add a diagnostic later on when this matches. diff --git a/src/Razor/Microsoft.CodeAnalysis.Razor/test/BindTagHelperDescriptorProviderTest.cs b/src/Razor/Microsoft.CodeAnalysis.Razor/test/BindTagHelperDescriptorProviderTest.cs index e037ab2fd1..dc8b6605ba 100644 --- a/src/Razor/Microsoft.CodeAnalysis.Razor/test/BindTagHelperDescriptorProviderTest.cs +++ b/src/Razor/Microsoft.CodeAnalysis.Razor/test/BindTagHelperDescriptorProviderTest.cs @@ -432,6 +432,28 @@ namespace Test Assert.True(parameter.IsStringProperty); Assert.False(parameter.IsBooleanProperty); Assert.False(parameter.IsEnum); + + parameter = Assert.Single(attribute.BoundAttributeParameters, a => a.Name.Equals("culture")); + + // Invariants + Assert.Empty(parameter.Diagnostics); + Assert.False(parameter.HasErrors); + Assert.Equal(ComponentMetadata.Bind.TagHelperKind, parameter.Kind); + Assert.False(parameter.IsDefaultKind()); + + Assert.Equal( + "Specifies the culture to use for conversions.", + parameter.Documentation); + + Assert.Equal("culture", parameter.Name); + Assert.Equal("Culture", parameter.GetPropertyName()); + Assert.Equal(":culture", parameter.DisplayName); + + // Defined from the property type + Assert.Equal("System.Globalization.CultureInfo", parameter.TypeName); + Assert.False(parameter.IsStringProperty); + Assert.False(parameter.IsBooleanProperty); + Assert.False(parameter.IsEnum); } [Fact] @@ -847,8 +869,29 @@ namespace Test Assert.True(parameter.IsStringProperty); Assert.False(parameter.IsBooleanProperty); Assert.False(parameter.IsEnum); - } + parameter = Assert.Single(attribute.BoundAttributeParameters, a => a.Name.Equals("culture")); + + // Invariants + Assert.Empty(parameter.Diagnostics); + Assert.False(parameter.HasErrors); + Assert.Equal(ComponentMetadata.Bind.TagHelperKind, parameter.Kind); + Assert.False(parameter.IsDefaultKind()); + + Assert.Equal( + "Specifies the culture to use for conversions.", + parameter.Documentation); + + Assert.Equal("culture", parameter.Name); + Assert.Equal("Culture", parameter.GetPropertyName()); + Assert.Equal(":culture", parameter.DisplayName); + + // Defined from the property type + Assert.Equal("System.Globalization.CultureInfo", parameter.TypeName); + Assert.False(parameter.IsStringProperty); + Assert.False(parameter.IsBooleanProperty); + Assert.False(parameter.IsEnum); + } private static TagHelperDescriptor[] GetBindTagHelpers(TagHelperDescriptorProviderContext context) {