using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace RoslynExperiments
public static void Main()
var tree = CSharpSyntaxTree.ParseText(@"
using System.Collections.Generic;
List<int> list = new List<int>();
StringBuilder sb = new StringBuilder();
var syntaxRoot = tree.GetRoot();
var Mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location);
var compilation = CSharpCompilation.Create("MyCompilation", syntaxTrees: new[] { tree }, references: new[] { Mscorlib });
var model = compilation.GetSemanticModel(tree);
var MyNamespace = syntaxRoot.DescendantNodes().OfType<NamespaceDeclarationSyntax>().First();
var MyClass1 = MyNamespace.DescendantNodes().OfType<ClassDeclarationSyntax>().First(x => x.Identifier.Text == "MyClass1");
var MyClass2 = MyNamespace.DescendantNodes().OfType<ClassDeclarationSyntax>().First(x => x.Identifier.Text == "MyClass1");
var result = FindUsedUsings(model, MyClass1);
Console.WriteLine(result);
private static string FindUsedUsings(SemanticModel model, SyntaxNode node)
throw new NotImplementedException();