c#新手 有许多可用的框架接口(interface),如 iDisposable、Iqueryable、IEnumerable,它们有不同的用途 是否有可用于此类系统接口(interface)的列表,可以用作现成的引用
最佳答案
好吧,下面是我运行的快速脚本,用于扫描计算机的 .NET 程序集并找到其中定义的所有接口(interface)类型
输出文件是 1657 行长*,所以...您可能想稍微缩小搜索范围;)
Console.Write("Enter a path to write the list of interfaces to: ");
string savePath = Console.ReadLine();
var errors = new List<string>();
using (var writer = new StreamWriter(savePath))
{
string dotNetPath = @"C:\Windows\Microsoft.NET\Framework";
string[] dllFiles = Directory.GetFiles(dotNetPath, "*.dll", SearchOption.AllDirectories);
foreach (string dllFilePath in dllFiles)
{
try
{
Assembly assembly = Assembly.LoadFile(dllFilePath);
var interfaceTypes = assembly.GetTypes()
.Where(t => t.IsInterface);
foreach (Type interfaceType in interfaceTypes)
{
writer.WriteLine(interfaceType.FullName);
Console.WriteLine(interfaceType.FullName);
}
}
catch
{
errors.Add(string.Format("Unable to load assembly '{0}'.", dllFilePath));
}
}
}
foreach (string err in errors)
{
Console.WriteLine(err);
}
Console.ReadLine();
*老实说,我什至不知道这种方法有多全面。
关于c# - c# 中的框架接口(interface)列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3699674/