本文整理汇总了C#中ErrorSink类的典型用法代码示例。如果您正苦于以下问题:C# ErrorSink类的具体用法?C# ErrorSink怎么用?C# ErrorSink使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ErrorSink类属于命名空间,在下文中一共展示了ErrorSink类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Resolve_CalculatesAssemblyLocationInLookupText
public void Resolve_CalculatesAssemblyLocationInLookupText(string lookupText, int assemblyLocation)
{
// Arrange
var errorSink = new ErrorSink();
var tagHelperDescriptorResolver = new InspectableTagHelperDescriptorResolver();
var directiveType = TagHelperDirectiveType.AddTagHelper;
var resolutionContext = new TagHelperDescriptorResolutionContext(
new[]
{
new TagHelperDirectiveDescriptor
{
DirectiveText = lookupText,
Location = SourceLocation.Zero,
DirectiveType = directiveType
}
},
errorSink);
var expectedSourceLocation = new SourceLocation(assemblyLocation, 0, assemblyLocation);
// Act
tagHelperDescriptorResolver.Resolve(resolutionContext);
// Assert
Assert.Empty(errorSink.Errors);
Assert.Equal(expectedSourceLocation, tagHelperDescriptorResolver.DocumentLocation);
}
示例2: CreateDescriptors_WithPrefixes_ReturnsExpectedAttributeDescriptors
public void CreateDescriptors_WithPrefixes_ReturnsExpectedAttributeDescriptors(
Type tagHelperType,
IEnumerable<TagHelperAttributeDescriptor> expectedAttributeDescriptors,
string[] expectedErrorMessages)
{
// Arrange
var errorSink = new ErrorSink();
var factory = new TagHelperDescriptorFactory(designTime: false);
// Act
var descriptors = factory.CreateDescriptors(
AssemblyName,
GetTypeInfo(tagHelperType),
errorSink: errorSink);
// Assert
var errors = errorSink.Errors.ToArray();
Assert.Equal(expectedErrorMessages.Length, errors.Length);
for (var i = 0; i < errors.Length; i++)
{
Assert.Equal(0, errors[i].Length);
Assert.Equal(SourceLocation.Zero, errors[i].Location);
Assert.Equal(expectedErrorMessages[i], errors[i].Message, StringComparer.Ordinal);
}
var descriptor = Assert.Single(descriptors);
Assert.Equal(
expectedAttributeDescriptors,
descriptor.Attributes,
TagHelperAttributeDescriptorComparer.Default);
}
示例3: CreateDescriptors
/// <summary>
/// Creates a <see cref="TagHelperDescriptor"/> from the given <paramref name="typeInfo"/>.
/// </summary>
/// <param name="assemblyName">The assembly name that contains <paramref name="type"/>.</param>
/// <param name="typeInfo">The <see cref="ITypeInfo"/> to create a <see cref="TagHelperDescriptor"/> from.
/// </param>
/// <param name="errorSink">The <see cref="ErrorSink"/> used to collect <see cref="RazorError"/>s encountered
/// when creating <see cref="TagHelperDescriptor"/>s for the given <paramref name="typeInfo"/>.</param>
/// <returns>
/// A collection of <see cref="TagHelperDescriptor"/>s that describe the given <paramref name="typeInfo"/>.
/// </returns>
public virtual IEnumerable<TagHelperDescriptor> CreateDescriptors(
string assemblyName,
ITypeInfo typeInfo,
ErrorSink errorSink)
{
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
if (errorSink == null)
{
throw new ArgumentNullException(nameof(errorSink));
}
if (ShouldSkipDescriptorCreation(typeInfo))
{
return Enumerable.Empty<TagHelperDescriptor>();
}
var attributeDescriptors = GetAttributeDescriptors(typeInfo, errorSink);
var targetElementAttributes = GetValidHtmlTargetElementAttributes(typeInfo, errorSink);
var allowedChildren = GetAllowedChildren(typeInfo, errorSink);
var tagHelperDescriptors =
BuildTagHelperDescriptors(
typeInfo,
assemblyName,
attributeDescriptors,
targetElementAttributes,
allowedChildren);
return tagHelperDescriptors.Distinct(TagHelperDescriptorComparer.Default);
}
示例4: GetAttributeNameValuePairs_ParsesPairsCorrectly
public void GetAttributeNameValuePairs_ParsesPairsCorrectly(
string documentContent,
IEnumerable<KeyValuePair<string, string>> expectedPairs)
{
// Arrange
var errorSink = new ErrorSink();
var parseResult = ParseDocument(documentContent, errorSink);
var document = parseResult.Document;
var rewriters = RazorParser.GetDefaultRewriters(new HtmlMarkupParser());
var rewritingContext = new RewritingContext(document, errorSink);
foreach (var rewriter in rewriters)
{
rewriter.Rewrite(rewritingContext);
}
var block = rewritingContext.SyntaxTree.Children.First();
var parseTreeRewriter = new TagHelperParseTreeRewriter(provider: null);
// Assert - Guard
var tagBlock = Assert.IsType<Block>(block);
Assert.Equal(BlockType.Tag, tagBlock.Type);
Assert.Empty(errorSink.Errors);
// Act
var pairs = parseTreeRewriter.GetAttributeNameValuePairs(tagBlock);
// Assert
Assert.Equal(expectedPairs, pairs);
}
示例5: TagHelperDirectiveSpanVisitor
public TagHelperDirectiveSpanVisitor(
[NotNull] ITagHelperDescriptorResolver descriptorResolver,
[NotNull] ErrorSink errorSink)
{
_descriptorResolver = descriptorResolver;
_errorSink = errorSink;
}
示例6: RewritingContext
/// <summary>
/// Instantiates a new <see cref="RewritingContext"/>.
/// </summary>
public RewritingContext(Block syntaxTree, ErrorSink errorSink)
{
_errors = new List<RazorError>();
SyntaxTree = syntaxTree;
ErrorSink = errorSink;
}
示例7: GetValidTargetElementAttributes
private static IEnumerable<TargetElementAttribute> GetValidTargetElementAttributes(
TypeInfo typeInfo,
ErrorSink errorSink)
{
var targetElementAttributes = typeInfo.GetCustomAttributes<TargetElementAttribute>(inherit: false);
return targetElementAttributes.Where(attribute => ValidTargetElementAttributeNames(attribute, errorSink));
}
示例8: CreateParserContext
public override ParserContext CreateParserContext(
ITextDocument input,
ParserBase codeParser,
ParserBase markupParser,
ErrorSink errorSink)
{
return base.CreateParserContext(input, codeParser, markupParser, errorSink);
}
示例9: CompilerContext
public CompilerContext(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink, ParserSink parserSink)
{
Contract.RequiresNotNull(sourceUnit, "sourceUnit");
_sourceUnit = sourceUnit;
_options = options ?? sourceUnit.Engine.GetDefaultCompilerOptions();
_errors = errorSink ?? sourceUnit.Engine.GetCompilerErrorSink();
_parserSink = parserSink ?? ParserSink.Null;
}
示例10: CodeBuilderContext
// Internal for testing.
internal CodeBuilderContext(RazorEngineHost host,
string className,
string rootNamespace,
string sourceFile,
bool shouldGenerateLinePragmas,
ErrorSink errorSink)
: base(host, className, rootNamespace, sourceFile, shouldGenerateLinePragmas)
{
ErrorSink = errorSink;
ExpressionRenderingMode = ExpressionRenderingMode.WriteToOutput;
}
示例11: CompilerContext
public CompilerContext(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink, ParserSink parserSink) {
ContractUtils.RequiresNotNull(sourceUnit, "sourceUnit");
ContractUtils.RequiresNotNull(errorSink, "errorSink");
ContractUtils.RequiresNotNull(parserSink, "parserSink");
ContractUtils.RequiresNotNull(options, "options");
_sourceUnit = sourceUnit;
_options = options;
_errors = errorSink;
_parserSink = parserSink;
}
示例12: CreateParserContext
public virtual ParserContext CreateParserContext(ITextDocument input,
ParserBase codeParser,
ParserBase markupParser,
ErrorSink errorSink)
{
return new ParserContext(input,
codeParser,
markupParser,
SelectActiveParser(codeParser, markupParser),
errorSink);
}
示例13: Rewrite
public static TagHelperBlockBuilder Rewrite(
string tagName,
bool validStructure,
Block tag,
IEnumerable<TagHelperDescriptor> descriptors,
ErrorSink errorSink)
{
// There will always be at least one child for the '<'.
var start = tag.Children.First().Start;
var attributes = GetTagAttributes(tagName, validStructure, tag, descriptors, errorSink);
var tagMode = GetTagMode(tagName, tag, descriptors, errorSink);
return new TagHelperBlockBuilder(tagName, tagMode, start, attributes, descriptors);
}
示例14: VisitCallsOnCompleteWhenAllNodesHaveBeenVisited
public void VisitCallsOnCompleteWhenAllNodesHaveBeenVisited()
{
// Arrange
Mock<ParserVisitor> targetMock = new Mock<ParserVisitor>();
var root = new BlockBuilder() { Type = BlockType.Comment }.Build();
var errorSink = new ErrorSink();
errorSink.OnError(new RazorError("Foo", new SourceLocation(1, 0, 1), length: 3));
errorSink.OnError(new RazorError("Bar", new SourceLocation(2, 0, 2), length: 3));
var results = new ParserResults(root, Enumerable.Empty<TagHelperDescriptor>(), errorSink);
// Act
targetMock.Object.Visit(results);
// Assert
targetMock.Verify(v => v.OnComplete());
}
示例15: VisitSendsDocumentToVisitor
public void VisitSendsDocumentToVisitor()
{
// Arrange
Mock<ParserVisitor> targetMock = new Mock<ParserVisitor>();
var root = new BlockBuilder() { Type = BlockType.Comment }.Build();
var errorSink = new ErrorSink();
var results = new ParserResults(root,
Enumerable.Empty<TagHelperDescriptor>(),
errorSink);
// Act
targetMock.Object.Visit(results);
// Assert
targetMock.Verify(v => v.VisitBlock(root));
}