我有一个很长的 .cs 文件(很多这样的文件),为了加快安全审计,我想查看这个文件所引用的类的列表。
例如:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using OrganizationName;
namespace OurCodebase
{
public class NeedsAudit
{
public void DoSomething()
{
System.IO.File.ReadAllText( "" );
WebRequest wr = WebRequest.Create( "" );
OurFramework.Clients.Search( "*jason*" );
}
}
}
这应该会产生一个列表:
System.IO.File
System.Net.WebRequest
OrganizationName.OurFramework.Clients
有没有办法在 Visual Studio 中执行此操作,或者是否有一个程序可以解析代码并提取此列表?
最佳答案
你有很多选项我在几个项目中使用了 NDepend。 NDepend 提供的功能比您要求的要多得多,但它创建了依赖关系的可视化图表(阅读更多 here )
NDepend is a static analysis tool for .NET managed code. The tool supports a large number of code metrics, allowing to visualize dependencies using directed graphs and dependency matrix. The tool also performs code base snapshots comparisons, and validation of architectural and quality rules.
Visual Studio 2017 的 CodeMap 也可用于此类依赖项可视化任务。
You can visualize dependencies across your code by creating a code map. Code maps help you see how the code fits together without reading through files and lines of code.
关于C# - 获取源代码文件正在使用或引用的类型列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52212919/