static void Main(string[] args)
        {
            var tree = CSharpSyntaxTree.ParseText(@"
using System;
using System.Collections.Generic;
class Program {
  static void Main(string[] args) {
    var x = 5;
    var s = ""Test string"";
    var l = new List<string>();
    var scores = new byte[8][]; // Test comment
    var names = new string[3] {""Diego"", ""Dani"", ""Seba""};
  }
}");

            // Get the assembly file, the compilation and the semantic model
            var Mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location);
            var compilation = CSharpCompilation.Create("RoslynVarRewrite",
              syntaxTrees: new[] { tree },
              references: new[] { Mscorlib });
            var model = compilation.GetSemanticModel(tree);

            var varRewriter = new VarRewriter(model);
            var result = varRewriter.Visit(tree.GetRoot());
            Console.WriteLine(result.ToFullString());
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var tree = CSharpSyntaxTree.ParseText(@"
using System;
using System.Collections.Generic;
class Program {
  static void Main(string[] args) {
    var x = 5;
    var s = ""Test string"";
    var l = new List<string>();
    var scores = new byte[8][]; // Test comment
    var names = new string[3] {""Diego"", ""Dani"", ""Seba""};
  }
}");

            // Get the assembly file, the compilation and the semantic model
            var Mscorlib    = MetadataReference.CreateFromFile(typeof(object).Assembly.Location);
            var compilation = CSharpCompilation.Create("RoslynVarRewrite",
                                                       syntaxTrees: new[] { tree },
                                                       references: new[] { Mscorlib });
            var model = compilation.GetSemanticModel(tree);

            var varRewriter = new VarRewriter(model);
            var result      = varRewriter.Visit(tree.GetRoot());

            Console.WriteLine(result.ToFullString());
        }