// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.TagHelpers; namespace Microsoft.AspNet.Razor { /// /// Represents the results of parsing a Razor document /// public class ParserResults { /// /// Instantiates a new instance. /// /// The for the syntax tree. /// /// The s that apply to the current Razor document. /// /// /// The used to collect s encountered when parsing the /// current Razor document. /// public ParserResults(Block document, IEnumerable tagHelperDescriptors, ErrorSink errorSink) : this(!errorSink.Errors.Any(), document, tagHelperDescriptors, errorSink) { if (document == null) { throw new ArgumentNullException(nameof(document)); } if (tagHelperDescriptors == null) { throw new ArgumentNullException(nameof(tagHelperDescriptors)); } if (errorSink == null) { throw new ArgumentNullException(nameof(errorSink)); } } /// /// Instantiates a new instance. /// /// true if parsing was successful, false otherwise. /// The for the syntax tree. /// /// The s that apply to the current Razor document. /// /// /// The used to collect s encountered when parsing the /// current Razor document. /// protected ParserResults(bool success, Block document, IEnumerable tagHelperDescriptors, ErrorSink errorSink) { if (document == null) { throw new ArgumentNullException(nameof(document)); } if (tagHelperDescriptors == null) { throw new ArgumentNullException(nameof(tagHelperDescriptors)); } if (errorSink == null) { throw new ArgumentNullException(nameof(errorSink)); } Success = success; Document = document; TagHelperDescriptors = tagHelperDescriptors; ErrorSink = errorSink; ParserErrors = errorSink.Errors; Prefix = tagHelperDescriptors.FirstOrDefault()?.Prefix; } /// /// Indicates if parsing was successful (no errors). /// /// true if parsing was successful, false otherwise. public bool Success { get; } /// /// The root node in the document's syntax tree. /// public Block Document { get; } /// /// Used to aggregate s. /// public ErrorSink ErrorSink { get; } /// /// The list of errors which occurred during parsing. /// public IEnumerable ParserErrors { get; } /// /// The s found for the current Razor document. /// public IEnumerable TagHelperDescriptors { get; } /// /// Text used as a required prefix when matching HTML. /// public string Prefix { get; } } }