Advertisement
Suchiman

Untitled

Sep 14th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using Microsoft.CodeAnalysis;
  2. using Microsoft.CodeAnalysis.CSharp;
  3. using Microsoft.CodeAnalysis.Text;
  4.  
  5. namespace ConsoleApplication2
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             SourceText origSourceText = SourceText.From("class Test { }");
  12.             SyntaxTree origSyntaxTree = SyntaxFactory.ParseSyntaxTree(origSourceText);
  13.  
  14.             TextChange textChange = new TextChange(new TextSpan(12, 0), "public void Test() {}");
  15.             SourceText changedSourceText = origSourceText.WithChanges(textChange);
  16.             SyntaxTree changedSyntaxTree = origSyntaxTree.WithChangedText(changedSourceText);
  17.  
  18.             string src = changedSyntaxTree.GetCompilationUnitRoot().NormalizeWhitespace().ToString();
  19.             /*src
  20.             class Test
  21.             {
  22.                 public void Test()
  23.                 {
  24.                 }
  25.             }
  26.             */
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement