问题
In previous version of Roslyn I could add custom data to SyntaxNode
with using class derived from SyntaxAnnotation
. But now SyntaxAnnotation
is sealed and I can use SyntaxAnnotation
only with to strings: kind and data. It is not enough for me. I want to build custom CFG from AST and make bidirectional links between CFG and AST nodes.
How I can do that?
回答1:
SyntaxAnnotation
is sealed because your tree may be serialized, and we need to be able to serialize and deserialize the annotations. If you want to store more info, then store the strings you use for annotations as a key to a dictionary containing the state.
来源:https://stackoverflow.com/questions/27260603/how-to-add-custom-syntax-annotation-to-syntaxnode