Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Commit

Permalink
Modify TryGetAttributes to return a IReadOnlyList
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkm committed Dec 28, 2015
1 parent dbe4ce0 commit 77b74b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.AspNet.Razor.TagHelpers
{
Expand All @@ -17,6 +16,13 @@ namespace Microsoft.AspNet.Razor.TagHelpers
public class ReadOnlyTagHelperAttributeList<TAttribute> : IReadOnlyList<TAttribute>
where TAttribute : IReadOnlyTagHelperAttribute
{
private static readonly IReadOnlyList<TAttribute> EmptyList =
#if NET451
new TAttribute[0];
#else
Array.Empty<TAttribute>();
#endif

/// <summary>
/// Instantiates a new instance of <see cref="ReadOnlyTagHelperAttributeList{TAttribute}"/> with an empty
/// collection.
Expand Down Expand Up @@ -190,12 +196,11 @@ public bool TryGetAttribute(string name, out TAttribute attribute)
/// <param name="name">The <see cref="IReadOnlyTagHelperAttribute.Name"/> of the
/// <typeparamref name="TAttribute"/>s to get.</param>
/// <param name="attributes">When this method returns, the <typeparamref name="TAttribute"/>s with
/// <see cref="IReadOnlyTagHelperAttribute.Name"/> matching <paramref name="name"/>, if at least one is
/// found; otherwise, <c>null</c>.</param>
/// <see cref="IReadOnlyTagHelperAttribute.Name"/> matching <paramref name="name"/>.</param>
/// <returns><c>true</c> if at least one <typeparamref name="TAttribute"/> with the same
/// <see cref="IReadOnlyTagHelperAttribute.Name"/> exists in the collection; otherwise, <c>false</c>.</returns>
/// <remarks><paramref name="name"/> is compared case-insensitively.</remarks>
public bool TryGetAttributes(string name, out IEnumerable<TAttribute> attributes)
public bool TryGetAttributes(string name, out IReadOnlyList<TAttribute> attributes)
{
if (name == null)
{
Expand All @@ -216,7 +221,7 @@ public bool TryGetAttributes(string name, out IEnumerable<TAttribute> attributes
matchedAttributes.Add(Attributes[i]);
}
}
attributes = matchedAttributes ?? Enumerable.Empty<TAttribute>();
attributes = matchedAttributes ?? EmptyList;

return matchedAttributes != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ public void TryGetAttributes_ReturnsExpectedValueAndAttribute(
{
// Arrange
var attributes = new ReadOnlyTagHelperAttributeList<IReadOnlyTagHelperAttribute>(initialAttributes);
IEnumerable<IReadOnlyTagHelperAttribute> resolvedAttributes;
IReadOnlyList<IReadOnlyTagHelperAttribute> resolvedAttributes;

// Act
var result = attributes.TryGetAttributes(nameToLookup, out resolvedAttributes);
Expand Down

0 comments on commit 77b74b0

Please sign in to comment.