如何向 SyntaxNode 添加自定义语法注释? [英] How to add custom syntax annotation to SyntaxNode?

查看:64
本文介绍了如何向 SyntaxNode 添加自定义语法注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在先前版本的 Roslyn 中,我可以使用从 SyntaxAnnotation 派生的类将自定义数据添加到 SyntaxNode.但是现在 SyntaxAnnotation 是密封的,我只能将 SyntaxAnnotation 用于字符串:种类和数据.这对我来说还不够.我想从 AST 构建自定义 CFG 并在 CFG 和 AST 节点之间建立双向链接.

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.

我该怎么做?

推荐答案

SyntaxAnnotation 是密封的,因为你的树可能被序列化,我们需要能够序列化和反序列化注释.如果要存储更多信息,请将用于注释的字符串存储为包含状态的字典的键.

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.

这篇关于如何向 SyntaxNode 添加自定义语法注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆