This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tree = CSharpSyntaxTree.ParseText(@" | |
class MyClass | |
class MyClass | |
{ | |
int myField1, myField2, myField3; | |
}"); | |
var Mscorlib = PortableExecutableReference.CreateFromAssembly(typeof(object).Assembly); | |
var compilation = CSharpCompilation.Create("MyCompilation", | |
syntaxTrees: new[] { tree }, references: new[] { Mscorlib }); | |
var model = compilation.GetSemanticModel(tree); | |
var field = tree.GetRoot().DescendantNodes().OfType<FieldDeclarationSyntax>().Single(); | |
foreach (var variable in field.Declaration.Variables) | |
{ | |
//Now we can access each of the symbols within the field | |
var fieldSymbol = model.GetDeclaredSymbol(variable); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment