如果我有以下标签助手:
[Flags]
public enum SubresourceIntegrityHashAlgorithm
{
SHA256 = 1,
SHA384 = 2,
SHA512 = 4
}
[HtmlTargetElement("script", Attributes = "asp-subresource-integrity")]
public class FooTagHelper : TagHelper
{
[HtmlAttributeName("asp-subresource-integrity")]
public SubresourceIntegrityHashAlgorithm HashAlgorithms { get; set; }
= SubresourceIntegrityHashAlgorithm.SHA256;
public override void Process(TagHelperContext context, TagHelperOutput output)
{
// ...
}
}
如何使用我在上面的属性上给出的默认值,以便在使用时不必为属性提供值:
<script asp-subresource-integrity src="..."></script>
代替:
<script asp-subresource-integrity="SubresourceIntegrityHashAlgorithm.SHA256" src="..."></script>
更新
我在 MVC GitHub 页面上提出了一个问题,因为这确实应该是一个内置功能。