/// <summary> /// Builds a snippet from extracted syntax nodes. /// </summary> /// <param name="nodes">The exctracted nodes.</param> /// <param name="extractionMode">The extraction mode.</param> /// <returns>The built snippet.</returns> private string BuildSnippet(SyntaxNode[] nodes, CSharpExtractionMode extractionMode) { if(nodes == null || !nodes.Any()) { throw new ArgumentException("'nodes' is null or empty"); } // Extract code from each snippets StringBuilder stringBuilder = new StringBuilder(); bool firstSnippet = true; foreach (SyntaxNode node in nodes) { // Write line return between each snippet if (!firstSnippet) { stringBuilder.AppendLine(); stringBuilder.AppendLine(); } // Write each snippet line string[] lines = node.GetText().Lines.Select(x => x.ToString()).ToArray(); int contentPosition = this.DetermineContentPosition(node); this.WriteAndCleanupSnippet(stringBuilder, lines, extractionMode, contentPosition); // Flag the first snippet as false firstSnippet = false; } // Create the snippet from the exctracted code return stringBuilder.ToString(); }