diff --git a/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/ReadOnlyTagHelperAttributeList.cs b/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/ReadOnlyTagHelperAttributeList.cs index 714805643d..161309a46f 100644 --- a/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/ReadOnlyTagHelperAttributeList.cs +++ b/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/ReadOnlyTagHelperAttributeList.cs @@ -4,7 +4,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Linq; namespace Microsoft.AspNet.Razor.TagHelpers { @@ -17,6 +16,13 @@ namespace Microsoft.AspNet.Razor.TagHelpers public class ReadOnlyTagHelperAttributeList : IReadOnlyList where TAttribute : IReadOnlyTagHelperAttribute { + private static readonly IReadOnlyList EmptyList = +#if NET451 + new TAttribute[0]; +#else + Array.Empty(); +#endif + /// /// Instantiates a new instance of with an empty /// collection. @@ -190,12 +196,11 @@ namespace Microsoft.AspNet.Razor.TagHelpers /// The of the /// s to get. /// When this method returns, the s with - /// matching , if at least one is - /// found; otherwise, null. + /// 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 IEnumerable attributes) + public bool TryGetAttributes(string name, out IReadOnlyList attributes) { if (name == null) { @@ -216,7 +221,7 @@ namespace Microsoft.AspNet.Razor.TagHelpers matchedAttributes.Add(Attributes[i]); } } - attributes = matchedAttributes ?? Enumerable.Empty(); + attributes = matchedAttributes ?? EmptyList; return matchedAttributes != null; } diff --git a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/ReadOnlyTagHelperAttributeListTest.cs b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/ReadOnlyTagHelperAttributeListTest.cs index 42e0bfbe6a..d4e13865aa 100644 --- a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/ReadOnlyTagHelperAttributeListTest.cs +++ b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/ReadOnlyTagHelperAttributeListTest.cs @@ -587,7 +587,7 @@ namespace Microsoft.AspNet.Razor.TagHelpers { // Arrange var attributes = new ReadOnlyTagHelperAttributeList(initialAttributes); - IEnumerable resolvedAttributes; + IReadOnlyList resolvedAttributes; // Act var result = attributes.TryGetAttributes(nameToLookup, out resolvedAttributes);