[英]Building .Net Code Analysis Tool
I am looking to create .net code analysis tool based on custom rules. 我希望基于自定义规则创建.net代码分析工具。 i am going to use reflection to read entire code.
我将使用反射来读取整个代码。 Is there any way to read number of line consumed in class or method using reflection or any other assembly.
有什么方法可以使用反射或任何其他程序集读取类或方法中消耗的行数。
I am thinking to use some opensource tool so i can do modification in it but unable to find it on Google. 我正在考虑使用一些开源工具,以便可以对其进行修改,但无法在Google上找到它。
Suggestions are welcome! 欢迎提出建议! thx
谢谢
Is there any way to read number of line consumed in class or method using reflection or any other assembly.
有什么方法可以使用反射或任何其他程序集读取类或方法中消耗的行数。
This is not possible. 这是不可能的。 The best you could do is to inspect the
MethodBody
for each MethodInfo
which 最好的办法是检查每个
MethodInfo
的MethodBody
Provides access to the metadata and MSIL for the body of a method.
提供对方法主体的元数据和MSIL的访问。
but lines of code is not something you can get. 但是您无法获得代码行。 The number of lines is entirely a source code property and cannot be obtained through reflection.
行数完全是源代码属性,无法通过反射获得。
Does 是否
int x; x = 1; doSomethingWith(x);
count as one, two, or three lines? 算作一,二或三行? What about this:
那这个呢:
int x;
x = 1;
doSomethingWith(x);
Lines of code is very rarely a useful metric - see, eg " When, if ever, is “number of lines of code” a useful metric? " 代码行很少是有用的度量标准-例如,请参阅“ 何时,如果有的话,“代码行数”是否是有用的度量标准? ”
As Ira Baxter pointed out, you should probably look at Roslyn. 正如艾拉·巴克斯特(Ira Baxter)所指出的,您可能应该看看罗斯林(Roslyn)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.