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
AdhocWorkspace workspace = new AdhocWorkspace(); | |
Project project = workspace.AddProject("SampleProject", LanguageNames.CSharp); | |
//Attach a syntax annotation to the class declaration | |
var syntaxAnnotation = new SyntaxAnnotation(); | |
var classDeclaration = SyntaxFactory.ClassDeclaration("MyClass") | |
.WithAdditionalAnnotations(syntaxAnnotation); | |
var compilationUnit = SyntaxFactory.CompilationUnit().AddMembers(classDeclaration); | |
Document document = project.AddDocument("SampleDocument.cs", compilationUnit); | |
SemanticModel semanticModel = document.GetSemanticModelAsync().Result; | |
//Use the annotation on our original node to find the new class declaration | |
var changedClass = document.GetSyntaxRootAsync().Result.DescendantNodes().OfType<ClassDeclarationSyntax>() | |
.Where(n => n.HasAnnotation(syntaxAnnotation)).Single(); | |
var symbol = semanticModel.GetDeclaredSymbol(changedClass); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment