Skip to content

Instantly share code, notes, and snippets.

@JoshVarty
Last active October 19, 2015 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshVarty/52a7699f4d4ce4099c2d to your computer and use it in GitHub Desktop.
Save JoshVarty/52a7699f4d4ce4099c2d to your computer and use it in GitHub Desktop.
var tree = CSharpSyntaxTree.ParseText(@"
public class MyClass
{
int MyMethod() { return 0; }
}");
var Mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location);
var compilation = CSharpCompilation.Create("MyCompilation",
syntaxTrees: new[] { tree }, references: new[] { Mscorlib });
//Note that we must specify the tree for which we want the model.
//Each tree has its own semantic model
var model = compilation.GetSemanticModel(tree);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment