c# - .NET/C# - 反射 - 曾经使用过的 System.IO.File

标签 c# .net reflection

有没有办法使用反射来完全“扫描”一个程序集,看看是否使用过 System.IO.File 或 System.IO.Directory?这些只是示例类。只是想知道是否有办法通过反射来做到这一点(与代码分析相比)。

更新: 看评论

最佳答案

正如 Tommy Carlier 所建议的,使用 Cecil 很容易做到.

using Mono.Cecil;

// ..

var assembly = AssemblyFactory.GetAssembly ("Foo.Bar.dll");
var module = assembly.MainModule;

bool references_file = module.TypeReferences.Contains ("System.IO.File");

关于c# - .NET/C# - 反射 - 曾经使用过的 System.IO.File,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1106322/

相关文章:

go - 如何实现通用 slice 附加器?

c# - 如何使用 Visual Studio 2017 自动将光标放在自己行的大括号之间

c# - 有效地将 IEnumerable 值折叠在一起

.net - 如何在VB.net中的2D数组中查找行数?

c# - 线程 : Thread. CurrentThread.Name 和 Thread.CurrentThread.ManagedThereadId

c# - 无法在 Visual Studio 2008 中创建 list 资源名称错误

python - 如何测试一个类是否包含特定属性?

c# - 无法让 double.TryParse 在 Linq 表达式树中工作

c# - 文本框自动完成字符串集合建议

c# - 使用 C# 以编程方式检测 Windows 登录尝试