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:
parent
c789ff1eb5
commit
53d60159f9
|
|
@ -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"/>.
|
||||
|
|
|
|||
|
|
@ -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"/>.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue