diff --git a/src/Microsoft.AspNetCore.Razor.Runtime/Properties/Resources.Designer.cs b/src/Microsoft.AspNetCore.Razor.Runtime/Properties/Resources.Designer.cs
index 3b10a1fd0b..b9da9197b7 100644
--- a/src/Microsoft.AspNetCore.Razor.Runtime/Properties/Resources.Designer.cs
+++ b/src/Microsoft.AspNetCore.Razor.Runtime/Properties/Resources.Designer.cs
@@ -362,38 +362,6 @@ namespace Microsoft.AspNetCore.Razor.Runtime
return string.Format(CultureInfo.CurrentCulture, GetString("TagHelperDescriptorFactory_InvalidAttributePrefixNotNull"), p0, p1, p2, p3, p4);
}
- ///
- /// Cannot add a '{0}' with a null '{1}'.
- ///
- internal static string TagHelperAttributeList_CannotAddWithNullName
- {
- get { return GetString("TagHelperAttributeList_CannotAddWithNullName"); }
- }
-
- ///
- /// Cannot add a '{0}' with a null '{1}'.
- ///
- internal static string FormatTagHelperAttributeList_CannotAddWithNullName(object p0, object p1)
- {
- return string.Format(CultureInfo.CurrentCulture, GetString("TagHelperAttributeList_CannotAddWithNullName"), p0, p1);
- }
-
- ///
- /// Cannot add a {0} with inconsistent names. The {1} property '{2}' must match the location '{3}'.
- ///
- internal static string TagHelperAttributeList_CannotAddAttribute
- {
- get { return GetString("TagHelperAttributeList_CannotAddAttribute"); }
- }
-
- ///
- /// Cannot add a {0} with inconsistent names. The {1} property '{2}' must match the location '{3}'.
- ///
- internal static string FormatTagHelperAttributeList_CannotAddAttribute(object p0, object p1, object p2, object p3)
- {
- return string.Format(CultureInfo.CurrentCulture, GetString("TagHelperAttributeList_CannotAddAttribute"), p0, p1, p2, p3);
- }
-
///
/// Invalid '{0}' tag name '{1}' for tag helper '{2}'. Tag helpers cannot restrict child elements that contain a '{3}' character.
///
diff --git a/src/Microsoft.AspNetCore.Razor.Runtime/Resources.resx b/src/Microsoft.AspNetCore.Razor.Runtime/Resources.resx
index cfc6719220..a3d55d9bcf 100644
--- a/src/Microsoft.AspNetCore.Razor.Runtime/Resources.resx
+++ b/src/Microsoft.AspNetCore.Razor.Runtime/Resources.resx
@@ -183,12 +183,6 @@
Invalid tag helper bound property '{0}.{1}'. '{2}.{3}' must be null unless property type implements '{4}'.
-
- Cannot add a '{0}' with a null '{1}'.
-
-
- Cannot add a {0} with inconsistent names. The {1} property '{2}' must match the location '{3}'.
-
Invalid '{0}' tag name '{1}' for tag helper '{2}'. Tag helpers cannot restrict child elements that contain a '{3}' character.
diff --git a/src/Microsoft.AspNetCore.Razor.Runtime/Runtime/TagHelpers/TagHelperExecutionContext.cs b/src/Microsoft.AspNetCore.Razor.Runtime/Runtime/TagHelpers/TagHelperExecutionContext.cs
index f17a1536a2..9126524c52 100644
--- a/src/Microsoft.AspNetCore.Razor.Runtime/Runtime/TagHelpers/TagHelperExecutionContext.cs
+++ b/src/Microsoft.AspNetCore.Razor.Runtime/Runtime/TagHelpers/TagHelperExecutionContext.cs
@@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Razor.Runtime.TagHelpers
_endTagHelperWritingScope = endTagHelperWritingScope;
TagMode = tagMode;
- HTMLAttributes = new TagHelperAttributeList();
+ HtmlAttributes = new TagHelperAttributeList();
AllAttributes = new TagHelperAttributeList();
TagName = tagName;
Items = items;
@@ -125,7 +125,7 @@ namespace Microsoft.AspNetCore.Razor.Runtime.TagHelpers
///
/// HTML attributes.
///
- public TagHelperAttributeList HTMLAttributes { get; }
+ public TagHelperAttributeList HtmlAttributes { get; }
///
/// bound attributes and HTML attributes.
@@ -173,7 +173,7 @@ namespace Microsoft.AspNetCore.Razor.Runtime.TagHelpers
}
///
- /// Tracks the minimized HTML attribute in and .
+ /// Tracks the minimized HTML attribute in and .
///
/// The minimized HTML attribute name.
public void AddMinimizedHtmlAttribute(string name)
@@ -183,22 +183,13 @@ namespace Microsoft.AspNetCore.Razor.Runtime.TagHelpers
throw new ArgumentNullException(nameof(name));
}
- HTMLAttributes.Add(
- new TagHelperAttribute
- {
- Name = name,
- Minimized = true
- });
- AllAttributes.Add(
- new TagHelperAttribute
- {
- Name = name,
- Minimized = true
- });
+ var attribute = new TagHelperAttribute(name);
+ HtmlAttributes.Add(attribute);
+ AllAttributes.Add(attribute);
}
///
- /// Tracks the HTML attribute in and .
+ /// Tracks the HTML attribute in and .
///
/// The HTML attribute name.
/// The HTML attribute value.
@@ -209,7 +200,7 @@ namespace Microsoft.AspNetCore.Razor.Runtime.TagHelpers
throw new ArgumentNullException(nameof(name));
}
- HTMLAttributes.Add(name, value);
+ HtmlAttributes.Add(name, value);
AllAttributes.Add(name, value);
}
diff --git a/src/Microsoft.AspNetCore.Razor.Runtime/Runtime/TagHelpers/TagHelperRunner.cs b/src/Microsoft.AspNetCore.Razor.Runtime/Runtime/TagHelpers/TagHelperRunner.cs
index 91f3057525..7e11d150d2 100644
--- a/src/Microsoft.AspNetCore.Razor.Runtime/Runtime/TagHelpers/TagHelperRunner.cs
+++ b/src/Microsoft.AspNetCore.Razor.Runtime/Runtime/TagHelpers/TagHelperRunner.cs
@@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Razor.Runtime.TagHelpers
var tagHelperOutput = new TagHelperOutput(
executionContext.TagName,
- executionContext.HTMLAttributes,
+ executionContext.HtmlAttributes,
executionContext.GetChildContentAsync)
{
TagMode = executionContext.TagMode,
diff --git a/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/IReadOnlyTagHelperAttribute.cs b/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/IReadOnlyTagHelperAttribute.cs
deleted file mode 100644
index f7883299b8..0000000000
--- a/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/IReadOnlyTagHelperAttribute.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-
-namespace Microsoft.AspNetCore.Razor.TagHelpers
-{
- ///
- /// A read-only HTML tag helper attribute.
- ///
- public interface IReadOnlyTagHelperAttribute : IEquatable
- {
- ///
- /// Gets the name of the attribute.
- ///
- string Name { get; }
-
- ///
- /// Gets the value of the attribute.
- ///
- object Value { get; }
-
- ///
- /// Gets an indication whether the attribute is minimized or not.
- ///
- /// If true, will be ignored.
- bool Minimized { get; }
- }
-}
\ No newline at end of file
diff --git a/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/ReadOnlyTagHelperAttributeList.cs b/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/ReadOnlyTagHelperAttributeList.cs
index bf4ad973fd..441c1e8451 100644
--- a/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/ReadOnlyTagHelperAttributeList.cs
+++ b/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/ReadOnlyTagHelperAttributeList.cs
@@ -2,73 +2,52 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
-using System.Collections;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
namespace Microsoft.AspNetCore.Razor.TagHelpers
{
///
- /// A read-only collection of s.
+ /// A read-only collection of s.
///
- ///
- /// The type of s in the collection.
+ ///
+ /// The type of s in the collection.
///
- public class ReadOnlyTagHelperAttributeList : IReadOnlyList
- where TAttribute : IReadOnlyTagHelperAttribute
+ public abstract class ReadOnlyTagHelperAttributeList : ReadOnlyCollection
{
- private static readonly IReadOnlyList EmptyList =
-#if NET451
- new TAttribute[0];
-#else
- Array.Empty();
-#endif
+ private static readonly IReadOnlyList EmptyList = new TagHelperAttribute[0];
///
- /// Instantiates a new instance of with an empty
+ /// Instantiates a new instance of with an empty
/// collection.
///
protected ReadOnlyTagHelperAttributeList()
+ : base(new List())
{
- Attributes = new List();
}
///
- /// Instantiates a new instance of with the specified
+ /// Instantiates a new instance of with the specified
/// .
///
/// The collection to wrap.
- public ReadOnlyTagHelperAttributeList(IEnumerable attributes)
+ public ReadOnlyTagHelperAttributeList(IEnumerable attributes)
+ : base(new List(attributes))
{
- if (attributes == null)
- {
- throw new ArgumentNullException(nameof(attributes));
- }
-
- Attributes = new List(attributes);
}
///
- /// The underlying collection of s.
- ///
- /// Intended for use in a non-read-only subclass. Changes to this will
- /// affect all getters that provides.
- protected List Attributes { get; }
-
- ///
- public TAttribute this[int index] => Attributes[index];
-
- ///
- /// Gets the first with
+ /// Gets the first with
/// matching .
///
///
- /// The of the to get.
+ /// The of the to get.
///
- /// The first with
+ /// The first with
/// matching .
///
/// is compared case-insensitively.
- public TAttribute this[string name]
+ public TagHelperAttribute this[string name]
{
get
{
@@ -78,106 +57,47 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
}
// Perf: Avoid allocating enumerator
- for (var i = 0; i < Attributes.Count; i++)
+ for (var i = 0; i < Items.Count; i++)
{
- if (NameEquals(name, Attributes[i]))
+ if (NameEquals(name, Items[i]))
{
- return Attributes[i];
+ return Items[i];
}
}
- return default(TAttribute);
+ return null;
}
}
- ///
- public int Count => Attributes.Count;
-
///
- /// Determines whether a matching exists in the
- /// collection.
+ /// Determines whether a with
+ /// matching exists in the collection.
///
- /// The to locate.
+ /// The of the
+ /// to get.
///
- /// true if an matching exists in the
- /// collection; otherwise, false.
- ///
- ///
- /// s is compared case-insensitively.
- ///
- public bool Contains(TAttribute item)
- {
- if (item == null)
- {
- throw new ArgumentNullException(nameof(item));
- }
-
- return Attributes.Contains(item);
- }
-
- ///
- /// Determines whether a with the same
- /// exists in the collection.
- ///
- /// The of the
- /// to get.
- ///
- /// true if a with the same
- /// exists in the collection; otherwise, false.
+ /// true if a with the same
+ /// exists in the collection; otherwise, false.
///
/// is compared case-insensitively.
public bool ContainsName(string name)
{
- if (name == null)
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- // Perf: Avoid allocating enumerator
- for (var i = 0; i < Attributes.Count; i++)
- {
- if (NameEquals(name, Attributes[i]))
- {
- return true;
- }
- }
-
- return false;
+ return this[name] != null;
}
///
- /// Searches for a matching in the collection and
- /// returns the zero-based index of the first occurrence.
- ///
- /// The to locate.
- /// The zero-based index of the first occurrence of a matching
- /// in the collection, if found; otherwise, –1.
- ///
- /// s is compared case-insensitively.
- ///
- public int IndexOf(TAttribute item)
- {
- if (item == null)
- {
- throw new ArgumentNullException(nameof(item));
- }
-
- return Attributes.IndexOf(item);
- }
-
- ///
- /// Retrieves the first with
+ /// Retrieves the first with
/// matching .
///
- /// The of the
- /// to get.
- /// When this method returns, the first with
- /// matching , if found; otherwise,
+ /// The of the
+ /// to get.
+ /// When this method returns, the first with
+ /// matching , if found; otherwise,
/// null.
- /// true if a with the same
- /// exists in the collection; otherwise, false.
+ /// true if a with the same
+ /// exists in the collection; otherwise, false.
/// is compared case-insensitively.
- public bool TryGetAttribute(string name, out TAttribute attribute)
+ public bool TryGetAttribute(string name, out TagHelperAttribute attribute)
{
if (name == null)
{
@@ -190,17 +110,17 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
}
///
- /// Retrieves s in the collection with
- /// matching .
+ /// Retrieves s in the collection with
+ /// matching .
///
- /// The of the
- /// s to get.
- /// When this method returns, the s with
- /// matching .
- /// true if at least one with the same
- /// exists in the collection; otherwise, false.
+ /// The of the
+ /// s to get.
+ /// When this method returns, the s with
+ /// matching .
+ /// true if at least one with the same
+ /// exists in the collection; otherwise, false.
/// is compared case-insensitively.
- public bool TryGetAttributes(string name, out IReadOnlyList attributes)
+ public bool TryGetAttributes(string name, out IReadOnlyList attributes)
{
if (name == null)
{
@@ -208,17 +128,17 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
}
// Perf: Avoid allocating enumerator
- List matchedAttributes = null;
- for (var i = 0; i < Attributes.Count; i++)
+ List matchedAttributes = null;
+ for (var i = 0; i < Items.Count; i++)
{
- if (NameEquals(name, Attributes[i]))
+ if (NameEquals(name, Items[i]))
{
if (matchedAttributes == null)
{
- matchedAttributes = new List();
+ matchedAttributes = new List();
}
- matchedAttributes.Add(Attributes[i]);
+ matchedAttributes.Add(Items[i]);
}
}
attributes = matchedAttributes ?? EmptyList;
@@ -226,16 +146,30 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
return matchedAttributes != null;
}
- ///
- IEnumerator IEnumerable.GetEnumerator()
+ ///
+ /// Searches for a who's
+ /// case-insensitively matches and returns the zero-based index of the first
+ /// occurrence.
+ ///
+ /// The to locate in the collection.
+ /// The zero-based index of the first matching within the collection,
+ /// if found; otherwise, -1.
+ public int IndexOfName(string name)
{
- return GetEnumerator();
- }
+ if (name == null)
+ {
+ throw new ArgumentNullException(nameof(name));
+ }
- ///
- public IEnumerator GetEnumerator()
- {
- return Attributes.GetEnumerator();
+ for (var i = 0; i < Items.Count; i++)
+ {
+ if (NameEquals(name, Items[i]))
+ {
+ return i;
+ }
+ }
+
+ return -1;
}
///
@@ -246,7 +180,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
/// The attribute to compare against.
/// true if case-insensitively matches s
/// .
- protected static bool NameEquals(string name, TAttribute attribute)
+ protected static bool NameEquals(string name, TagHelperAttribute attribute)
{
if (attribute == null)
{
diff --git a/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelperAttribute.cs b/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelperAttribute.cs
index a96d1086b9..259e428d54 100644
--- a/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelperAttribute.cs
+++ b/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelperAttribute.cs
@@ -2,83 +2,77 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
+using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Razor.TagHelpers
{
///
/// An HTML tag helper attribute.
///
- public class TagHelperAttribute : IReadOnlyTagHelperAttribute
+ public class TagHelperAttribute
{
- private static readonly int TypeHashCode = typeof(TagHelperAttribute).GetHashCode();
-
///
- /// Instantiates a new instance of .
+ /// Instantiates a new instance of with the specified .
+ /// is set to true and to null.
///
- public TagHelperAttribute()
+ /// The of the attribute.
+ public TagHelperAttribute(string name)
+ : this(name, value: null, minimized: true)
{
}
- ///
- /// Instantiates a new instance of with values provided by the given
- /// .
- ///
- /// A whose values should be copied.
- public TagHelperAttribute(IReadOnlyTagHelperAttribute attribute)
- : this(attribute?.Name, attribute?.Value)
- {
- if (attribute == null)
- {
- throw new ArgumentNullException(nameof(attribute));
- }
-
- Minimized = attribute.Minimized;
- }
-
///
/// Instantiates a new instance of with the specified
- /// and .
+ /// and . is set to false.
///
/// The of the attribute.
/// The of the attribute.
public TagHelperAttribute(string name, object value)
+ : this(name, value, minimized: false)
{
+ }
+
+ ///
+ /// Instantiates a new instance of with the specified ,
+ /// and .
+ ///
+ /// The of the new instance.
+ /// The of the new instance.
+ /// The value of the new instance.
+ /// If is true, is ignored when this
+ /// instance is rendered.
+ public TagHelperAttribute(string name, object value, bool minimized)
+ {
+ if (name == null)
+ {
+ throw new ArgumentNullException(nameof(name));
+ }
+
Name = name;
Value = value;
+ Minimized = minimized;
}
///
- /// Gets or sets the name of the attribute.
+ /// Gets the name of the attribute.
///
- public string Name { get; set; }
+ public string Name { get; }
///
- /// Gets or sets the value of the attribute.
+ /// Gets the value of the attribute.
///
- public object Value { get; set; }
+ public object Value { get; }
///
- /// Gets or sets an indication whether the attribute is minimized or not.
+ /// Gets an indication whether the attribute is minimized or not.
///
/// If true, will be ignored.
- public bool Minimized { get; set; }
+ public bool Minimized { get; }
- ///
- /// Converts the specified into a .
- ///
- /// The of the created .
- /// Created s is set to null.
- public static implicit operator TagHelperAttribute(string value)
- {
- return new TagHelperAttribute
- {
- Value = value
- };
- }
///
/// is compared case-insensitively.
- public bool Equals(IReadOnlyTagHelperAttribute other)
+ public bool Equals(TagHelperAttribute other)
{
return
other != null &&
@@ -90,7 +84,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
///
public override bool Equals(object obj)
{
- var other = obj as IReadOnlyTagHelperAttribute;
+ var other = obj as TagHelperAttribute;
return Equals(other);
}
@@ -98,7 +92,12 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
///
public override int GetHashCode()
{
- return TypeHashCode;
+ var hashCodeCombiner = HashCodeCombiner.Start();
+ hashCodeCombiner.Add(Name, StringComparer.Ordinal);
+ hashCodeCombiner.Add(Value);
+ hashCodeCombiner.Add(Minimized);
+
+ return hashCodeCombiner.CombinedHash;
}
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelperAttributeList.cs b/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelperAttributeList.cs
index 419e92c87a..73dde2f667 100644
--- a/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelperAttributeList.cs
+++ b/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelperAttributeList.cs
@@ -3,14 +3,13 @@
using System;
using System.Collections.Generic;
-using Microsoft.AspNetCore.Razor.Runtime;
namespace Microsoft.AspNetCore.Razor.TagHelpers
{
///
/// A collection of s.
///
- public class TagHelperAttributeList : ReadOnlyTagHelperAttributeList, IList
+ public class TagHelperAttributeList : ReadOnlyTagHelperAttributeList, IList
{
///
/// Instantiates a new instance of with an empty collection.
@@ -51,123 +50,76 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
throw new ArgumentNullException(nameof(value));
}
- if (value.Name == null)
- {
- throw new ArgumentException(
- Resources.FormatTagHelperAttributeList_CannotAddWithNullName(
- typeof(TagHelperAttribute).FullName,
- nameof(TagHelperAttribute.Name)),
- nameof(value));
- }
-
- Attributes[index] = value;
+ Items[index] = value;
}
}
///
- /// Gets the first with matching
- /// . When setting, replaces the first matching
- /// with the specified and removes any additional
- /// matching s. If a matching is not found,
- /// adds the specified to the end of the collection.
- ///
+ /// Replaces the first with matching
+ /// and removes any additional matching s. If a
+ /// matching is not found, adds a with
+ /// and to the end of the collection.
///
- /// The of the to get or set.
+ /// The of the to set.
///
- /// The first with matching
- /// .
- ///
- /// is compared case-insensitively. When setting,
- /// s must be null or
- /// case-insensitively match the specified .
- ///
- ///
- /// var attributes = new TagHelperAttributeList();
- ///
- /// // Will "value" be converted to a TagHelperAttribute with a null Name
- /// attributes["name"] = "value";
- ///
- /// // TagHelperAttribute.Name must match the specified name.
- /// attributes["name"] = new TagHelperAttribute("name", "value");
- ///
- ///
- public new TagHelperAttribute this[string name]
+ ///
+ /// The to set.
+ ///
+ /// is compared case-insensitively.
+ public void SetAttribute(string name, object value)
{
- get
- {
- if (name == null)
- {
- throw new ArgumentNullException(nameof(name));
- }
+ var attribute = new TagHelperAttribute(name, value);
+ SetAttribute(attribute);
+ }
- return base[name];
+ ///
+ /// Replaces the first with matching
+ /// 's and removes any additional matching
+ /// s. If a matching is not found, adds the
+ /// specified to the end of the collection.
+ ///
+ ///
+ /// The to set.
+ ///
+ /// 's is compared
+ /// case-insensitively.
+ public void SetAttribute(TagHelperAttribute attribute)
+ {
+ if (attribute == null)
+ {
+ throw new ArgumentNullException(nameof(attribute));
}
- set
+
+ var attributeReplaced = false;
+
+ // Perf: Avoid allocating enumerator
+ for (var i = 0; i < Items.Count; i++)
{
- if (name == null)
+ if (NameEquals(attribute.Name, Items[i]))
{
- throw new ArgumentNullException(nameof(name));
- }
-
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- // Name will be null if user attempts to set the attribute via an implicit conversion:
- // output.Attributes["someName"] = "someValue"
- if (value.Name == null)
- {
- value.Name = name;
- }
- else if (!NameEquals(name, value))
- {
- throw new ArgumentException(
- Resources.FormatTagHelperAttributeList_CannotAddAttribute(
- nameof(TagHelperAttribute),
- nameof(TagHelperAttribute.Name),
- value.Name,
- name),
- nameof(name));
- }
-
- var attributeReplaced = false;
-
- // Perf: Avoid allocating enumerator
- for (var i = 0; i < Attributes.Count; i++)
- {
- if (NameEquals(name, Attributes[i]))
+ // We replace the first attribute with the provided attribute, remove all the rest.
+ if (!attributeReplaced)
{
- // We replace the first attribute with the provided value, remove all the rest.
- if (!attributeReplaced)
- {
- // We replace the first attribute we find with the same name.
- Attributes[i] = value;
- attributeReplaced = true;
- }
- else
- {
- Attributes.RemoveAt(i--);
- }
+ // We replace the first attribute we find with the same name.
+ Items[i] = attribute;
+ attributeReplaced = true;
+ }
+ else
+ {
+ Items.RemoveAt(i--);
}
}
+ }
- // If we didn't replace an attribute value we should add value to the end of the collection.
- if (!attributeReplaced)
- {
- Add(value);
- }
+ // If we didn't replace an attribute value we should add value to the end of the collection.
+ if (!attributeReplaced)
+ {
+ Add(attribute);
}
}
///
- bool ICollection.IsReadOnly
- {
- get
- {
- return false;
- }
- }
+ bool ICollection.IsReadOnly => false;
///
/// Adds a to the end of the collection with the specified
@@ -177,18 +129,11 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
/// The of the attribute to add.
public void Add(string name, object value)
{
- if (name == null)
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- Attributes.Add(new TagHelperAttribute(name, value));
+ var attribute = new TagHelperAttribute(name, value);
+ Items.Add(attribute);
}
///
- ///
- /// 's must not be null.
- ///
public void Add(TagHelperAttribute attribute)
{
if (attribute == null)
@@ -196,22 +141,10 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
throw new ArgumentNullException(nameof(attribute));
}
- if (attribute.Name == null)
- {
- throw new ArgumentException(
- Resources.FormatTagHelperAttributeList_CannotAddWithNullName(
- typeof(TagHelperAttribute).FullName,
- nameof(TagHelperAttribute.Name)),
- nameof(attribute));
- }
-
- Attributes.Add(attribute);
+ Items.Add(attribute);
}
///
- ///
- /// 's must not be null.
- ///
public void Insert(int index, TagHelperAttribute attribute)
{
if (attribute == null)
@@ -219,27 +152,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
throw new ArgumentNullException(nameof(attribute));
}
- if (attribute.Name == null)
- {
- throw new ArgumentException(
- Resources.FormatTagHelperAttributeList_CannotAddWithNullName(
- typeof(TagHelperAttribute).FullName,
- nameof(TagHelperAttribute.Name)),
- nameof(attribute));
- }
-
- Attributes.Insert(index, attribute);
- }
-
- ///
- public void CopyTo(TagHelperAttribute[] array, int index)
- {
- if (array == null)
- {
- throw new ArgumentNullException(nameof(array));
- }
-
- Attributes.CopyTo(array, index);
+ Items.Insert(index, attribute);
}
///
@@ -253,13 +166,13 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
throw new ArgumentNullException(nameof(attribute));
}
- return Attributes.Remove(attribute);
+ return Items.Remove(attribute);
}
///
public void RemoveAt(int index)
{
- Attributes.RemoveAt(index);
+ Items.RemoveAt(index);
}
///
@@ -282,11 +195,11 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
// Perf: Avoid allocating enumerator
var removedAtLeastOne = false;
- for (var i = Attributes.Count - 1; i >= 0; i--)
+ for (var i = Items.Count - 1; i >= 0; i--)
{
- if (NameEquals(name, Attributes[i]))
+ if (NameEquals(name, Items[i]))
{
- Attributes.RemoveAt(i);
+ Items.RemoveAt(i);
removedAtLeastOne = true;
}
}
@@ -297,7 +210,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
///
public void Clear()
{
- Attributes.Clear();
+ Items.Clear();
}
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelperContext.cs b/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelperContext.cs
index 5f7d590e5d..6cc4d1c437 100644
--- a/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelperContext.cs
+++ b/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelperContext.cs
@@ -11,8 +11,8 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
///
public class TagHelperContext
{
- private ReadOnlyTagHelperAttributeList _allAttributes;
- private IEnumerable _allAttributesData;
+ private ReadOnlyTagHelperAttributeList _allAttributes;
+ private IEnumerable _allAttributesData;
///
/// Instantiates a new .
@@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
/// The unique identifier for the source element this
/// applies to.
public TagHelperContext(
- IEnumerable allAttributes,
+ IEnumerable allAttributes,
IDictionary