gpt4 book ai didi

C# - 获取源代码文件正在使用或引用的类型列表

转载 作者:太空宇宙 更新时间:2023-11-03 19:42:00 25 4
gpt4 key购买 nike

我有一个很长的 .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 也可用于此类依赖项可视化任务。

CodeMap Page On MSDN :

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.

Map dependencies with code maps

关于C# - 获取源代码文件正在使用或引用的类型列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52212919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com