public string ToYamlString() { var parsingErrorsDetected = ParsingErrors.Any(); var builder = new StringBuilder() .Append("type: ").AppendLine("file") .Append("name: ").AppendLine(Name) .Append("locationSpan: ").AppendLine(LocationSpan.ToYamlString()) .Append("footerSpan: ").AppendLine(FooterSpan.ToYamlString()) .Append("parsingErrorsDetected: ").AppendLine(parsingErrorsDetected.ToString()); if (Children.Any()) { builder.AppendLine("children: "); foreach (var child in Children) { builder.AppendLine("- "); child.FillYamlString(builder, 3); builder.AppendLine(); } } if (parsingErrorsDetected) { builder.AppendLine("parsingError: "); foreach (var parsingError in ParsingErrors) { builder.AppendLine("- "); parsingError.FillYamlString(builder, 3); builder.AppendLine(); } } return(builder.ToString()); }