本文整理汇总了C#中Microsoft.AspNet.Razor.Runtime.TagHelpers.DefaultTagHelperContent.Append方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultTagHelperContent.Append方法的具体用法?C# DefaultTagHelperContent.Append怎么用?C# DefaultTagHelperContent.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNet.Razor.Runtime.TagHelpers.DefaultTagHelperContent
的用法示例。
在下文中一共展示了DefaultTagHelperContent.Append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyHtmlAttribute_DoesNotOverrideAttributes
public void CopyHtmlAttribute_DoesNotOverrideAttributes()
{
// Arrange
var attributeName = "hello";
var tagHelperOutput = new TagHelperOutput(
"p",
attributes: new Dictionary<string, object>()
{
{ attributeName, "world2" }
});
var expectedAttribute = new KeyValuePair<string, object>(attributeName, "world2");
var tagHelperContext = new TagHelperContext(
allAttributes: new Dictionary<string, object>(StringComparer.Ordinal)
{
{ attributeName, "world" }
},
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () =>
{
var tagHelperContent = new DefaultTagHelperContent();
tagHelperContent.Append("Something Else");
return Task.FromResult<TagHelperContent>(tagHelperContent);
});
// Act
tagHelperOutput.CopyHtmlAttribute(attributeName, tagHelperContext);
// Assert
var attribute = Assert.Single(tagHelperOutput.Attributes);
Assert.Equal(expectedAttribute, attribute);
}
示例2: CanAppendContent
public void CanAppendContent()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
var expected = "Hello World!";
// Act
tagHelperContent.Append(expected);
// Assert
Assert.Equal(expected, tagHelperContent.GetContent());
}
示例3: CanAppendContent
public void CanAppendContent()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
var expected = "HtmlEncode[[Hello World!]]";
// Act
tagHelperContent.Append("Hello World!");
// Assert
Assert.Equal(expected, tagHelperContent.GetContent(new CommonTestEncoder()));
}
示例4: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
if (ShowDismiss)
{
output.PreContent.AppendFormat(@"<button type='button' class='btn btn-default' data-dismiss='modal'>{0}</button>", DismissText);
}
var childContent = await context.GetChildContentAsync();
var footerContent = new DefaultTagHelperContent();
if (ShowDismiss)
{
footerContent.AppendFormat(@"<button type='button' class='btn btn-default' data-dismiss='modal'>{0}</button>", DismissText);
}
footerContent.Append(childContent);
var modalContext = (ModalContext)context.Items[typeof(ModalTagHelper)];
modalContext.Footer = footerContent;
output.SuppressOutput();
}
示例5: IsModified_TrueAfterAppend
public void IsModified_TrueAfterAppend()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
// Act
tagHelperContent.Append(string.Empty);
// Assert
Assert.True(tagHelperContent.IsModified);
}
示例6: GetEnumerator_EnumeratesThroughBuffer
public void GetEnumerator_EnumeratesThroughBuffer()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
var expected = new string[] { "Hello", "World" };
tagHelperContent.SetContent(expected[0]);
tagHelperContent.Append(expected[1]);
var i = 0;
// Act & Assert
foreach (var val in tagHelperContent)
{
Assert.Equal(expected[i++], val);
}
}
示例7: BuildFallbackBlock
private void BuildFallbackBlock(TagHelperAttributeList attributes, DefaultTagHelperContent builder)
{
EnsureGlobbingUrlBuilder();
EnsureFileVersionProvider();
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.Append(Environment.NewLine)
.Append("<script>(")
.Append(FallbackTestExpression)
.Append("||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.Append("<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 (FileVersion == 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.Append("><\\/script>");
}
builder.Append("\"));</script>");
}
}
示例8: IsEmpty_TrueAfterAppendEmptyTagHelperContent
public void IsEmpty_TrueAfterAppendEmptyTagHelperContent()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
var copiedTagHelperContent = new DefaultTagHelperContent();
// Act
tagHelperContent.Append(copiedTagHelperContent);
tagHelperContent.Append(string.Empty);
// Assert
Assert.True(tagHelperContent.IsEmpty);
}
示例9: IsEmpty_FalseAfterAppendTagHelper
public void IsEmpty_FalseAfterAppendTagHelper()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
var copiedTagHelperContent = new DefaultTagHelperContent();
copiedTagHelperContent.SetContent("Hello");
// Act
tagHelperContent.Append(copiedTagHelperContent);
// Assert
Assert.False(tagHelperContent.IsEmpty);
}
示例10: CanIdentifyWhiteSpace
public void CanIdentifyWhiteSpace(string data)
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
// Act
tagHelperContent.SetContent(" ");
tagHelperContent.Append(data);
// Assert
Assert.True(tagHelperContent.IsWhiteSpace);
}
示例11: CanIdentifyWhiteSpace_WithoutIgnoringStrings
public void CanIdentifyWhiteSpace_WithoutIgnoringStrings()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
// Act
tagHelperContent.SetContent(" ");
tagHelperContent.Append("Hello");
// Assert
Assert.False(tagHelperContent.IsWhiteSpace);
}
示例12: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var viewDictionary = modelContext.CurrentData;
if (viewDictionary == null)
{
await base.ProcessAsync(context, output);
return;
}
foreach (var attribute in BindAttributes)
{
if (
attribute.Key.StartsWith("bindattr-") ||
forbiddenForAny.Contains(attribute.Key) ||
(output.TagName.ToLower() == "view" && forbiddenForView.Contains(attribute.Key))
)
{
continue;
}
var value = modelContext.Value(attribute.Value);
output.Attributes.Add($"bindattr-{attribute.Key}", attribute.Value);
if (true.Equals(value))
{
output.Attributes.Add(attribute.Key, string.Empty);
}
else if (!false.Equals(value))
{
output.Attributes.Add(attribute.Key, value);
}
}
if (!string.IsNullOrWhiteSpace(BindCount))
{
output.Attributes.Add("bindcount", BindCount);
var value = modelContext.Value(BindCount) as IEnumerable;
if (value == null)
{
output.Content.SetContent(0.ToString());
}
else
{
output.Content.SetContent(value.Cast<object>().Count().ToString());
}
}
else if (!string.IsNullOrWhiteSpace(BindText))
{
output.Attributes.Add("bindtext", BindText);
var value = modelContext.Value(BindText);
output.Content.SetContent(helper.Encode(value));
}
else if (!string.IsNullOrWhiteSpace(BindHtml))
{
output.Attributes.Add("bindhtml", BindHtml);
var value = modelContext.Value(BindHtml);
output.Content.SetContent(helper.Raw(value).ToString());
}
else if (!string.IsNullOrWhiteSpace(BindSome))
{
output.Attributes.Add("bindsome", BindSome);
var value = modelContext.Value(BindSome) as IEnumerable;
if (value != null && value.Cast<object>().Any())
{
ViewDataDictionary originalData;
TagHelperContent template;
TagHelperContent buffer;
originalData = modelContext.CurrentData;
modelContext.Initialize(new object());
buffer = new DefaultTagHelperContent();
template = await context.GetChildContentAsync();
// commit a8fd85d to aspnet/Razor will make this cleaner:
// buffer.Append(await context.GetChildContentAsync(useCachedResult: false));
// for now just use reflection to hack it up
var delegateField = context.GetType().GetRuntimeFields().Single(f => f.Name == "_getChildContentAsync");
var @delegate = delegateField.GetValue(context);
var targetField = delegateField.FieldType.GetRuntimeProperties().Single(p => p.Name == "Target");
var @target = targetField.GetValue(@delegate);
var hackField = @target.GetType().GetRuntimeFields().Single(f => f.Name == "_childContent");
foreach (var item in value)
{
hackField.SetValue(@target, null);
modelContext.Initialize(item);
buffer.Append(await context.GetChildContentAsync());
}
output.Content.SetContent(buffer);
modelContext.CurrentData = originalData;
}
else
{
output.Attributes.Add("hidden", true);
//.........这里部分代码省略.........
示例13: IsModified_TrueIfAppendedNull
public void IsModified_TrueIfAppendedNull()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
TagHelperContent NullContent = null;
// Act
tagHelperContent.Append(NullContent);
// Assert
Assert.True(tagHelperContent.IsModified);
}
示例14: Append_WithTagHelperContent_MultipleAppends
public void Append_WithTagHelperContent_MultipleAppends()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
var copiedTagHelperContent = new DefaultTagHelperContent();
var text1 = "Hello";
var text2 = " World!";
var expected = text1 + text2;
tagHelperContent.Append(text1);
tagHelperContent.Append(text2);
// Act
copiedTagHelperContent.Append(tagHelperContent);
// Assert
Assert.Equal(expected, copiedTagHelperContent.GetContent());
Assert.Equal(new[] { text1, text2 }, copiedTagHelperContent.ToArray());
}
示例15: MakeTagHelperContext
private static TagHelperContext MakeTagHelperContext(
TagHelperAttributeList attributes = null,
string content = null)
{
attributes = attributes ?? new TagHelperAttributeList();
return new TagHelperContext(
attributes,
items: new Dictionary<object, object>(),
uniqueId: Guid.NewGuid().ToString("N"),
getChildContentAsync: useCachedResult =>
{
var tagHelperContent = new DefaultTagHelperContent();
tagHelperContent.Append(content);
return Task.FromResult((TagHelperContent)tagHelperContent);
});
}