本文整理汇总了C#中TagHelperAttributeList.ContainsName方法的典型用法代码示例。如果您正苦于以下问题:C# TagHelperAttributeList.ContainsName方法的具体用法?C# TagHelperAttributeList.ContainsName怎么用?C# TagHelperAttributeList.ContainsName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TagHelperAttributeList
的用法示例。
在下文中一共展示了TagHelperAttributeList.ContainsName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildFallbackBlock
private void BuildFallbackBlock(TagHelperAttributeList attributes, DefaultTagHelperContent builder)
{
EnsureGlobbingUrlBuilder();
var fallbackSrcs = GlobbingUrlBuilder.BuildUrlList(FallbackSrc, FallbackSrcInclude, FallbackSrcExclude);
if (fallbackSrcs.Any())
{
// Build the <script> tag that checks the test method and if it fails, renders the extra script.
builder.AppendHtml(Environment.NewLine)
.AppendHtml("<script>(")
.AppendHtml(FallbackTestExpression)
.AppendHtml("||document.write(\"");
// May have no "src" attribute in the dictionary e.g. if Src and SrcInclude were not bound.
if (!attributes.ContainsName(SrcAttributeName))
{
// Need this entry to place each fallback source.
attributes.Add(new TagHelperAttribute(SrcAttributeName, value: null));
}
foreach (var src in fallbackSrcs)
{
// Fallback "src" values come from bound attributes and globbing. Must always be non-null.
Debug.Assert(src != null);
builder.AppendHtml("<script");
foreach (var attribute in attributes)
{
if (!attribute.Name.Equals(SrcAttributeName, StringComparison.OrdinalIgnoreCase))
{
var encodedKey = JavaScriptEncoder.JavaScriptStringEncode(attribute.Name);
var attributeValue = attribute.Value.ToString();
var encodedValue = JavaScriptEncoder.JavaScriptStringEncode(attributeValue);
AppendAttribute(builder, encodedKey, encodedValue, escapeQuotes: true);
}
else
{
// Ignore attribute.Value; use src instead.
var attributeValue = src;
if (AppendVersion == true)
{
attributeValue = _fileVersionProvider.AddFileVersionToPath(attributeValue);
}
// attribute.Key ("src") does not need to be JavaScript-encoded.
var encodedValue = JavaScriptEncoder.JavaScriptStringEncode(attributeValue);
AppendAttribute(builder, attribute.Name, encodedValue, escapeQuotes: true);
}
}
builder.AppendHtml("><\\/script>");
}
builder.AppendHtml("\"));</script>");
}
}
示例2: ContainsName_ReturnsExpectedResult
public void ContainsName_ReturnsExpectedResult(
IEnumerable<TagHelperAttribute> initialAttributes,
string nameToLookup,
bool expected)
{
// Arrange
var attributes = new TagHelperAttributeList(initialAttributes);
// Act
var contains = attributes.ContainsName(nameToLookup);
// Assert
Assert.Equal(expected, contains);
}