哪些解析器可用于解析C#代码?
我正在寻找一个可以在C#中使用的C#解析器,让我可以访问有关所分析代码的每个人工制品的行和文件信息.
如何从C#源文件中删除所有注释和空行.请记住,可能存在嵌套注释.一些例子:
string text = @"//not a comment"; // a comment
/* multiline
comment */ string newText = "/*not a comment*/"; // a comment
/* multiline // not a comment
/* comment */ string anotherText = "/* not a comment */ // some text here\"// not a comment"; // a comment
Run Code Online (Sandbox Code Playgroud)
我们可以拥有比上面这三个例子更复杂的来源.有人可以建议使用正则表达式或其他方法来解决这个问题.我已经在互联网上浏览了很多东西,并且找不到任何可行的东西.
我需要一个正则表达式来捕获T-SQL块中的所有注释.Expression需要与.Net Regex类一起使用.
假设我有以下T-SQL:
-- This is Comment 1
SELECT Foo FROM Bar
GO
-- This is
-- Comment 2
UPDATE Bar SET Foo == 'Foo'
GO
/* This is Comment 3 */
DELETE FROM Bar WHERE Foo = 'Foo'
/* This is a
multi-line comment */
DROP TABLE Bar
Run Code Online (Sandbox Code Playgroud)
我需要捕获所有注释,包括多行注释,以便我可以删除它们.
编辑:它有同样的目的,有一个表达式,采取一切但评论.