使用 Roslyn 分析器检查源代码行是否超出行长度的最佳方法是什么?
我想对代码线长度执行一些硬限制。
我应该使用什么Roslyn的API?
为每个语法节点注册操作并检查节点的位置似乎不是最有效的方法。
I'd like to enforce some hard limits to code line length.
What Roslyn's API should I use for it?
Registering action for every syntax node and checking node's location seems to be not the most efficient approach.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不完美的解决方案:
Not perfect solution:
一种简单的方法可能是注册语法树,然后立即在语法树上调用 GetText() ;从那里您可以直接查看文本的行,并且至少找到“长”行,因为您可以通过这种方式直接获取行跨度和长度。您仍然可能需要过滤掉长字符串文字之类的东西。
An easy approach might be to register for syntax trees, but then immediately just call GetText() on the syntax tree; from there you can look at the lines of the text directly and at least find "long" lines since you can directly get line spans and lengths that way. You'll still potentially need to filter out things though like long string literals or something.