- use `[HtmlAttributeNotBound]` to make tag helper properties `public`
- properties remain invisible in Razor
This commit is contained in:
Doug Bunting 2015-04-24 23:48:18 -07:00
parent 838f672b10
commit c1622096b9
17 changed files with 74 additions and 95 deletions

View File

@ -24,9 +24,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
private const string RouteAttributePrefix = "asp-route-"; private const string RouteAttributePrefix = "asp-route-";
private const string Href = "href"; private const string Href = "href";
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public IHtmlGenerator Generator { get; set; }
protected internal IHtmlGenerator Generator { get; set; }
/// <summary> /// <summary>
/// The name of the action method. /// The name of the action method.

View File

@ -39,14 +39,14 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
/// <summary> /// <summary>
/// Gets or sets the <see cref="IMemoryCache"/> instance used to cache entries. /// Gets or sets the <see cref="IMemoryCache"/> instance used to cache entries.
/// </summary> /// </summary>
[Activate] [Activate, HtmlAttributeNotBound]
protected internal IMemoryCache MemoryCache { get; set; } public IMemoryCache MemoryCache { get; set; }
/// <summary> /// <summary>
/// Gets or sets the <see cref="ViewContext"/> for the current executing View. /// Gets or sets the <see cref="ViewContext"/> for the current executing View.
/// </summary> /// </summary>
[Activate] [Activate, HtmlAttributeNotBound]
protected internal ViewContext ViewContext { get; set; } public ViewContext ViewContext { get; set; }
/// <summary> /// <summary>
/// Gets or sets a <see cref="string" /> to vary the cached result by. /// Gets or sets a <see cref="string" /> to vary the cached result by.

View File

@ -25,9 +25,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
/// </remarks> /// </remarks>
public string Names { get; set; } public string Names { get; set; }
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public IHostingEnvironment HostingEnvironment { get; set; }
protected internal IHostingEnvironment HostingEnvironment { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public override void Process(TagHelperContext context, TagHelperOutput output) public override void Process(TagHelperContext context, TagHelperOutput output)

View File

@ -21,13 +21,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
private const string RouteAttributePrefix = "asp-route-"; private const string RouteAttributePrefix = "asp-route-";
private const string HtmlActionAttributeName = "action"; private const string HtmlActionAttributeName = "action";
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public ViewContext ViewContext { get; set; }
protected internal ViewContext ViewContext { get; set; }
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public IHtmlGenerator Generator { get; set; }
protected internal IHtmlGenerator Generator { get; set; }
/// <summary> /// <summary>
/// The name of the action method. /// The name of the action method.

View File

@ -62,13 +62,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{ "time", "{0:HH:mm:ss.fff}" }, { "time", "{0:HH:mm:ss.fff}" },
}; };
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public IHtmlGenerator Generator { get; set; }
protected internal IHtmlGenerator Generator { get; set; }
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public ViewContext ViewContext { get; set; }
protected internal ViewContext ViewContext { get; set; }
/// <summary> /// <summary>
/// An expression to be evaluated against the current model. /// An expression to be evaluated against the current model.

View File

@ -15,13 +15,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{ {
private const string ForAttributeName = "asp-for"; private const string ForAttributeName = "asp-for";
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public ViewContext ViewContext { get; set; }
protected internal ViewContext ViewContext { get; set; }
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public IHtmlGenerator Generator { get; set; }
protected internal IHtmlGenerator Generator { get; set; }
/// <summary> /// <summary>
/// An expression to be evaluated against the current model. /// An expression to be evaluated against the current model.

View File

@ -180,28 +180,27 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
[HtmlAttributeName(FallbackTestValueAttributeName)] [HtmlAttributeName(FallbackTestValueAttributeName)]
public string FallbackTestValue { get; set; } public string FallbackTestValue { get; set; }
// Properties are protected to ensure subclasses are correctly activated. [Activate, HtmlAttributeNotBound]
// Internal for ease of use when testing. public ILoggerFactory LoggerFactory { get; set; }
[Activate]
protected internal ILoggerFactory LoggerFactory { get; set; }
// TODO: will remove LoggerFactory and activate logger once DI/hosting bug is fixed // TODO: will remove LoggerFactory and activate logger once DI/hosting bug is fixed
internal ILogger<LinkTagHelper> Logger { get; set; } [HtmlAttributeNotBound]
public ILogger<LinkTagHelper> Logger { get; set; }
[Activate] [Activate, HtmlAttributeNotBound]
protected internal IHostingEnvironment HostingEnvironment { get; set; } public IHostingEnvironment HostingEnvironment { get; set; }
[Activate] [Activate, HtmlAttributeNotBound]
protected internal ViewContext ViewContext { get; set; } public ViewContext ViewContext { get; set; }
[Activate] [Activate, HtmlAttributeNotBound]
protected internal IMemoryCache Cache { get; set; } public IMemoryCache Cache { get; set; }
[Activate] [Activate, HtmlAttributeNotBound]
protected internal IHtmlEncoder HtmlEncoder { get; set; } public IHtmlEncoder HtmlEncoder { get; set; }
[Activate] [Activate, HtmlAttributeNotBound]
protected internal IJavaScriptStringEncoder JavaScriptEncoder { get; set; } public IJavaScriptStringEncoder JavaScriptEncoder { get; set; }
// Internal for ease of use when testing. // Internal for ease of use when testing.
protected internal GlobbingUrlBuilder GlobbingUrlBuilder { get; set; } protected internal GlobbingUrlBuilder GlobbingUrlBuilder { get; set; }

View File

@ -19,13 +19,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
/// </remarks> /// </remarks>
public class OptionTagHelper : TagHelper public class OptionTagHelper : TagHelper
{ {
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public IHtmlGenerator Generator { get; set; }
protected internal IHtmlGenerator Generator { get; set; }
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public ViewContext ViewContext { get; set; }
protected internal ViewContext ViewContext { get; set; }
/// <summary> /// <summary>
/// Specifies a value for the &lt;option&gt; element. /// Specifies a value for the &lt;option&gt; element.

View File

@ -149,27 +149,27 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
[HtmlAttributeName(FallbackTestExpressionAttributeName)] [HtmlAttributeName(FallbackTestExpressionAttributeName)]
public string FallbackTestExpression { get; set; } public string FallbackTestExpression { get; set; }
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public ILoggerFactory LoggerFactory { get; set; }
protected internal ILoggerFactory LoggerFactory { get; set; }
// TODO: will remove LoggerFactory and activate logger once DI/hosting bug is fixed // TODO: will remove LoggerFactory and activate logger once DI/hosting bug is fixed
internal ILogger<ScriptTagHelper> Logger { get; set; } [HtmlAttributeNotBound]
public ILogger<ScriptTagHelper> Logger { get; set; }
[Activate] [Activate, HtmlAttributeNotBound]
protected internal IHostingEnvironment HostingEnvironment { get; set; } public IHostingEnvironment HostingEnvironment { get; set; }
[Activate] [Activate, HtmlAttributeNotBound]
protected internal ViewContext ViewContext { get; set; } public ViewContext ViewContext { get; set; }
[Activate] [Activate, HtmlAttributeNotBound]
protected internal IMemoryCache Cache { get; set; } public IMemoryCache Cache { get; set; }
[Activate] [Activate, HtmlAttributeNotBound]
protected internal IHtmlEncoder HtmlEncoder { get; set; } public IHtmlEncoder HtmlEncoder { get; set; }
[Activate] [Activate, HtmlAttributeNotBound]
protected internal IJavaScriptStringEncoder JavaScriptEncoder { get; set; } public IJavaScriptStringEncoder JavaScriptEncoder { get; set; }
// Internal for ease of use when testing. // Internal for ease of use when testing.
protected internal GlobbingUrlBuilder GlobbingUrlBuilder { get; set; } protected internal GlobbingUrlBuilder GlobbingUrlBuilder { get; set; }

View File

@ -30,13 +30,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
/// </remarks> /// </remarks>
public static readonly string SelectedValuesFormDataKey = nameof(SelectTagHelper) + "-SelectedValues"; public static readonly string SelectedValuesFormDataKey = nameof(SelectTagHelper) + "-SelectedValues";
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public IHtmlGenerator Generator { get; set; }
protected internal IHtmlGenerator Generator { get; set; }
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public ViewContext ViewContext { get; set; }
protected internal ViewContext ViewContext { get; set; }
/// <summary> /// <summary>
/// An expression to be evaluated against the current model. /// An expression to be evaluated against the current model.

View File

@ -15,13 +15,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{ {
private const string ForAttributeName = "asp-for"; private const string ForAttributeName = "asp-for";
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public IHtmlGenerator Generator { get; set; }
protected internal IHtmlGenerator Generator { get; set; }
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public ViewContext ViewContext { get; set; }
protected internal ViewContext ViewContext { get; set; }
/// <summary> /// <summary>
/// An expression to be evaluated against the current model. /// An expression to be evaluated against the current model.

View File

@ -16,13 +16,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{ {
private const string ValidationForAttributeName = "asp-validation-for"; private const string ValidationForAttributeName = "asp-validation-for";
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public ViewContext ViewContext { get; set; }
protected internal ViewContext ViewContext { get; set; }
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public IHtmlGenerator Generator { get; set; }
protected internal IHtmlGenerator Generator { get; set; }
/// <summary> /// <summary>
/// Name to be validated on the current model. /// Name to be validated on the current model.

View File

@ -17,13 +17,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
private const string ValidationSummaryAttributeName = "asp-validation-summary"; private const string ValidationSummaryAttributeName = "asp-validation-summary";
private ValidationSummary _validationSummary; private ValidationSummary _validationSummary;
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public ViewContext ViewContext { get; set; }
protected internal ViewContext ViewContext { get; set; }
// Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate, HtmlAttributeNotBound]
[Activate] public IHtmlGenerator Generator { get; set; }
protected internal IHtmlGenerator Generator { get; set; }
/// <summary> /// <summary>
/// If <see cref="ValidationSummary.All"/> or <see cref="ValidationSummary.ModelOnly"/>, appends a validation /// If <see cref="ValidationSummary.All"/> or <see cref="ValidationSummary.ModelOnly"/>, appends a validation

View File

@ -147,7 +147,7 @@ namespace Microsoft.AspNet.Mvc.Razor
private class ServiceTagHelper : TagHelper private class ServiceTagHelper : TagHelper
{ {
[Activate] [Activate, HtmlAttributeNotBound]
public MyService ActivatedService { get; set; } public MyService ActivatedService { get; set; }
} }
@ -159,7 +159,7 @@ namespace Microsoft.AspNet.Mvc.Razor
private class ViewDataTagHelper : TagHelper private class ViewDataTagHelper : TagHelper
{ {
[Activate] [Activate, HtmlAttributeNotBound]
public ViewDataDictionary ViewData { get; set; } public ViewDataDictionary ViewData { get; set; }
} }

View File

@ -4,13 +4,12 @@
using System.Linq; using System.Linq;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.AspNet.Razor.TagHelpers;
namespace TagHelpersWebSite.TagHelpers namespace TagHelpersWebSite.TagHelpers
{ {
public class ATagHelper : TagHelper public class ATagHelper : TagHelper
{ {
[Activate] [Activate, HtmlAttributeNotBound]
public IUrlHelper UrlHelper { get; set; } public IUrlHelper UrlHelper { get; set; }
public string Controller { get; set; } public string Controller { get; set; }

View File

@ -25,7 +25,7 @@ namespace TagHelpersWebSite.TagHelpers
public string Style { get; set; } public string Style { get; set; }
[Activate] [Activate, HtmlAttributeNotBound]
public ViewContext ViewContext { get; set; } public ViewContext ViewContext { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output) public override void Process(TagHelperContext context, TagHelperOutput output)

View File

@ -4,7 +4,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.ViewComponents; using Microsoft.AspNet.Mvc.ViewComponents;
@ -26,7 +25,7 @@ namespace MvcSample.Web.Components
public int Count { get; set; } public int Count { get; set; }
[Activate] [Activate, HtmlAttributeNotBound]
public ViewContext ViewContext { get; set; } public ViewContext ViewContext { get; set; }
public int Order { get; } = 0; public int Order { get; } = 0;
@ -35,7 +34,7 @@ namespace MvcSample.Web.Components
{ {
var result = await InvokeAsync(Count); var result = await InvokeAsync(Count);
var writer = new StringWriter(); var writer = new StringWriter();
var viewComponentDescriptor = new ViewComponentDescriptor() var viewComponentDescriptor = new ViewComponentDescriptor()
{ {
Type = typeof(TagCloudViewComponentTagHelper), Type = typeof(TagCloudViewComponentTagHelper),