Add order property to control TagHelper execution order.

- Added order property to the ITagHelper class. Lower values indicates higher execution priority.

#94
This commit is contained in:
NTaylorMullen 2015-01-25 18:22:28 -08:00
parent c789ff1eb5
commit 53d60159f9
3 changed files with 13 additions and 1 deletions

View File

@ -10,6 +10,12 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// </summary>
public interface ITagHelper
{
/// <summary>
/// Gets the execution order of this <see cref= "ITagHelper" /> relative to others targeting the same element.
/// <see cref="ITagHelper"/> instances with lower values are executed first.
/// </summary>
int Order { get; }
/// <summary>
/// Asynchronously executes the <see cref="ITagHelper"/> with the given <paramref name="context"/> and
/// <paramref name="output"/>.

View File

@ -10,6 +10,10 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// </summary>
public abstract class TagHelper : ITagHelper
{
/// <inheritdoc />
/// <remarks>Default order is <c>0</c>.</remarks>
public virtual int Order { get; } = 0;
/// <summary>
/// Synchronously executes the <see cref="TagHelper"/> with the given <paramref name="context"/> and
/// <paramref name="output"/>.

View File

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
@ -24,8 +25,9 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
executionContext.UniqueId,
executionContext.GetChildContentAsync);
var tagHelperOutput = new TagHelperOutput(executionContext.TagName, executionContext.HTMLAttributes);
var orderedTagHelpers = executionContext.TagHelpers.OrderBy(tagHelper => tagHelper.Order);
foreach (var tagHelper in executionContext.TagHelpers)
foreach (var tagHelper in orderedTagHelpers)
{
await tagHelper.ProcessAsync(tagHelperContext, tagHelperOutput);
}