Add culture parameter to element-bind tag helpers

\n\nCommit migrated from 7515e2ce49
This commit is contained in:
Ryan Nowak 2019-06-30 15:28:46 -07:00 committed by Ryan Nowak
parent 66cb243807
commit 04d7e63b79
3 changed files with 66 additions and 1 deletions

View File

@ -129,6 +129,9 @@
<data name="BindTagHelper_Component_Documentation" xml:space="preserve">
<value>Binds the provided expression to the '{0}' property and a change event delegate to the '{1}' property of the component.</value>
</data>
<data name="BindTagHelper_Element_Culture_Documentation" xml:space="preserve">
<value>Specifies the culture to use for conversions.</value>
</data>
<data name="BindTagHelper_Element_Documentation" xml:space="preserve">
<value>Binds the provided expression to the '{0}' attribute and a change event delegate to the '{1}' attribute.</value>
</data>

View File

@ -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.

View File

@ -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)
{