Added HasIndexer property to BoundAttributeDescriptor

This commit is contained in:
Ajay Bhargav Baaskaran 2017-03-21 12:06:22 -07:00
parent 9aa4048866
commit c6a35e7b26
4 changed files with 57 additions and 17 deletions

View File

@ -27,12 +27,14 @@ namespace Microsoft.AspNetCore.Razor.Evolution
public string Name { get; protected set; }
public string IndexerNamePrefix { get; set; }
public string IndexerNamePrefix { get; protected set; }
public string TypeName { get; protected set; }
public string IndexerTypeName { get; protected set; }
public bool HasIndexer { get; protected set; }
public string Documentation { get; protected set; }
public string DisplayName { get; protected set; }

View File

@ -54,6 +54,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
string.Equals(descriptorX.Kind, descriptorY.Kind, StringComparison.Ordinal) &&
descriptorX.IsIndexerStringProperty == descriptorY.IsIndexerStringProperty &&
descriptorX.IsEnum == descriptorY.IsEnum &&
descriptorX.HasIndexer == descriptorY.HasIndexer &&
string.Equals(descriptorX.Name, descriptorY.Name, _stringComparison) &&
string.Equals(descriptorX.IndexerNamePrefix, descriptorY.IndexerNamePrefix, _stringComparison) &&
string.Equals(descriptorX.TypeName, descriptorY.TypeName, StringComparison.Ordinal) &&
@ -77,6 +78,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
hashCodeCombiner.Add(descriptor.Kind);
hashCodeCombiner.Add(descriptor.IsIndexerStringProperty);
hashCodeCombiner.Add(descriptor.IsEnum);
hashCodeCombiner.Add(descriptor.HasIndexer);
hashCodeCombiner.Add(descriptor.Name, _stringComparer);
hashCodeCombiner.Add(descriptor.IndexerNamePrefix, _stringComparer);
hashCodeCombiner.Add(descriptor.TypeName, StringComparer.Ordinal);

View File

@ -35,6 +35,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
new[] { '@', '!', '<', '/', '?', '[', '>', ']', '=', '"', '\'', '*' });
private bool _isEnum;
private bool _hasIndexer;
private string _indexerValueTypeName;
private string _name;
private string _propertyName;
@ -88,6 +89,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{
_indexerNamePrefix = attributeNamePrefix;
_indexerValueTypeName = valueTypeName;
_hasIndexer = true;
return this;
}
@ -136,6 +138,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
_typeName,
_indexerNamePrefix,
_indexerValueTypeName,
_hasIndexer,
_documentation,
displayName,
_metadata,
@ -256,6 +259,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
string typeName,
string dictionaryAttributeNamePrefix,
string dictionaryValueTypeName,
bool hasIndexer,
string documentation,
string displayName,
Dictionary<string, string> metadata,
@ -268,6 +272,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
TypeName = typeName;
IndexerNamePrefix = dictionaryAttributeNamePrefix;
IndexerTypeName = dictionaryValueTypeName;
HasIndexer = hasIndexer;
Documentation = documentation;
DisplayName = displayName;
Diagnostics = new List<RazorDiagnostic>(diagnostics);

View File

@ -1732,8 +1732,8 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
var dictionaryNamespace = typeof(IDictionary<,>).FullName;
dictionaryNamespace = dictionaryNamespace.Substring(0, dictionaryNamespace.IndexOf('`'));
// tagTelperType, expectedAttributeDescriptors
return new TheoryData<Type, IEnumerable<BoundAttributeDescriptor>>
// tagHelperType, expectedAttributeDescriptors, expectedDiagnostics
return new TheoryData<Type, IEnumerable<BoundAttributeDescriptor>, IEnumerable<RazorDiagnostic>>
{
{
typeof(DefaultValidHtmlAttributePrefix),
@ -1745,7 +1745,8 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.TypeName($"{dictionaryNamespace}<System.String, System.String>")
.AsDictionary("dictionary-property-", typeof(string).FullName)
.Build()
}
},
Enumerable.Empty<RazorDiagnostic>()
},
{
typeof(SingleValidHtmlAttributePrefix),
@ -1757,7 +1758,8 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.TypeName($"{dictionaryNamespace}<System.String, System.String>")
.AsDictionary("valid-name-", typeof(string).FullName)
.Build()
}
},
Enumerable.Empty<RazorDiagnostic>()
},
{
typeof(MultipleValidHtmlAttributePrefix),
@ -1808,7 +1810,8 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.TypeName($"{dictionaryNamespace}<System.String, System.String>")
.AsDictionary("valid-prefix6", typeof(string).FullName)
.Build()
}
},
Enumerable.Empty<RazorDiagnostic>()
},
{
typeof(SingleInvalidHtmlAttributePrefix),
@ -1818,11 +1821,16 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.Name("valid-name")
.PropertyName(nameof(SingleInvalidHtmlAttributePrefix.StringProperty))
.TypeName(typeof(string).FullName)
.AddDiagnostic(
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(SingleInvalidHtmlAttributePrefix).FullName,
nameof(SingleInvalidHtmlAttributePrefix.StringProperty)))
.AddDiagnostic(RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(SingleInvalidHtmlAttributePrefix).FullName,
nameof(SingleInvalidHtmlAttributePrefix.StringProperty)))
.Build(),
},
new[]
{
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(SingleInvalidHtmlAttributePrefix).FullName,
nameof(SingleInvalidHtmlAttributePrefix.StringProperty))
}
},
{
@ -1841,7 +1849,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.AsDictionary("valid-prefix2-", typeof(string).FullName)
.AddDiagnostic(
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.DictionaryOfIntProperty)))
.Build(),
ITagHelperBoundAttributeDescriptorBuilder.Create(typeof(MultipleInvalidHtmlAttributePrefix).FullName)
@ -1850,7 +1858,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.TypeName($"{typeof(IReadOnlyDictionary<,>).Namespace}.IReadOnlyDictionary<System.String, System.Object>")
.AddDiagnostic(
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.ReadOnlyDictionaryProperty)))
.Build(),
ITagHelperBoundAttributeDescriptorBuilder.Create(typeof(MultipleInvalidHtmlAttributePrefix).FullName)
@ -1859,7 +1867,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.TypeName(typeof(int).FullName)
.AddDiagnostic(
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.IntProperty)))
.Build(),
ITagHelperBoundAttributeDescriptorBuilder.Create(typeof(MultipleInvalidHtmlAttributePrefix).FullName)
@ -1869,7 +1877,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.AsDictionary("valid-prefix5-", typeof(string).FullName)
.AddDiagnostic(
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.DictionaryOfIntSubclassProperty)))
.Build(),
ITagHelperBoundAttributeDescriptorBuilder.Create(typeof(MultipleInvalidHtmlAttributePrefix).FullName)
@ -1878,7 +1886,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.AsDictionary("valid-prefix6", typeof(string).FullName)
.AddDiagnostic(
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.GetOnlyDictionaryAttributePrefix)))
.Build(),
ITagHelperBoundAttributeDescriptorBuilder.Create(typeof(MultipleInvalidHtmlAttributePrefix).FullName)
@ -1887,9 +1895,30 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
.AsDictionary("invalid-name7-", typeof(object).FullName)
.AddDiagnostic(
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.GetOnlyDictionaryPropertyWithAttributeName)))
.Build(),
},
new[]
{
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.DictionaryOfIntProperty)),
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.ReadOnlyDictionaryProperty)),
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.IntProperty)),
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.DictionaryOfIntSubclassProperty)),
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNotNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.GetOnlyDictionaryAttributePrefix)),
RazorDiagnosticFactory.CreateTagHelper_InvalidAttributePrefixNull(
typeof(MultipleInvalidHtmlAttributePrefix).FullName,
nameof(MultipleInvalidHtmlAttributePrefix.GetOnlyDictionaryPropertyWithAttributeName)),
}
},
};
@ -1900,7 +1929,8 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
[MemberData(nameof(TagHelperWithPrefixData))]
public void CreateDescriptor_WithPrefixes_ReturnsExpectedAttributeDescriptors(
Type tagHelperType,
IEnumerable<BoundAttributeDescriptor> expectedAttributeDescriptors)
IEnumerable<BoundAttributeDescriptor> expectedAttributeDescriptors,
IEnumerable<RazorDiagnostic> expectedDiagnostics)
{
// Arrange
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
@ -1914,6 +1944,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
expectedAttributeDescriptors,
descriptor.BoundAttributes,
BoundAttributeDescriptorComparer.CaseSensitive);
Assert.Equal(expectedDiagnostics, descriptor.GetAllDiagnostics());
}
public static TheoryData HtmlConversionData