Refactored internal class `TagHelperBlockTracker` slightly.

This commit is contained in:
N. Taylor Mullen 2015-09-18 17:29:19 -07:00
parent 0253c563be
commit 44675701cb
1 changed files with 17 additions and 7 deletions

View File

@ -572,22 +572,18 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal
private class TagHelperBlockTracker
{
private IEnumerable<string> _prefixedAllowedChildren;
public TagHelperBlockTracker(TagHelperBlockBuilder builder)
{
Builder = builder;
if (Builder.Descriptors.Any(descriptor => descriptor.AllowedChildren != null))
{
Debug.Assert(Builder.Descriptors.Count() >= 1);
var tagHelperPrefix = Builder.Descriptors.First().Prefix;
AllowedChildren = Builder.Descriptors
.Where(descriptor => descriptor.AllowedChildren != null)
.SelectMany(descriptor => descriptor.AllowedChildren)
.Distinct(StringComparer.OrdinalIgnoreCase);
PrefixedAllowedChildren = AllowedChildren.Select(allowedChild => tagHelperPrefix + allowedChild);
}
}
@ -597,7 +593,21 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal
public IEnumerable<string> AllowedChildren { get; }
public IEnumerable<string> PrefixedAllowedChildren { get; }
public IEnumerable<string> PrefixedAllowedChildren
{
get
{
if (AllowedChildren != null && _prefixedAllowedChildren == null)
{
Debug.Assert(Builder.Descriptors.Count() >= 1);
var prefix = Builder.Descriptors.First().Prefix;
_prefixedAllowedChildren = AllowedChildren.Select(allowedChild => prefix + allowedChild);
}
return _prefixedAllowedChildren;
}
}
}
}
}