C# c中的框架接口列表#

C# c中的框架接口列表#,c#,interface,C#,Interface,c中的新手# 有许多框架接口,如iDisposable、Iqueryable、IEnumerable,它们有不同的用途 是否有一个列表可用于此类系统接口,可用作现成的参考好,下面是我运行的一个快速脚本,用于扫描计算机的.NET程序集并查找其中定义的所有接口类型 输出文件长度为1657行,因此。。。您可能希望缩小搜索范围;) Console.Write(“输入将接口列表写入的路径:”); 字符串savePath=Console.ReadLine(); var errors=新列表(); 使用(va

c中的新手# 有许多框架接口,如iDisposable、Iqueryable、IEnumerable,它们有不同的用途
是否有一个列表可用于此类系统接口,可用作现成的参考

,下面是我运行的一个快速脚本,用于扫描计算机的.NET程序集并查找其中定义的所有接口类型

输出文件长度为1657行,因此。。。您可能希望缩小搜索范围;)

Console.Write(“输入将接口列表写入的路径:”);
字符串savePath=Console.ReadLine();
var errors=新列表();
使用(var writer=newstreamwriter(保存路径))
{
字符串dotNetPath=@“C:\Windows\Microsoft.NET\Framework”;
字符串[]dllFiles=Directory.GetFiles(dotNetPath,*.dll,SearchOption.AllDirectories);
foreach(dllFiles中的字符串dllFilePath)
{
尝试
{
Assembly=Assembly.LoadFile(dllFilePath);
var interfaceTypes=assembly.GetTypes()
.式中(t=>t.i界面);
foreach(在interfaceTypes中键入interfaceType)
{
writer.WriteLine(interfaceType.FullName);
Console.WriteLine(interfaceType.FullName);
}
}
抓住
{
Add(string.Format(“无法加载程序集“{0}.”,dllFilePath));
}
}
}
foreach(错误中的字符串错误)
{
控制台写入线(错误);
}
Console.ReadLine();

*老实说,我甚至不知道这种方法有多全面。

嗯,很多方法都是针对特定目的定制的。如果你把所有的都列出来,那需要一段时间

我要添加到上面的主要代码是
IList
/
IList
(集合/列表),
IDictionary
IEnumerable
(IEnumerable的通用版本)和
IEnumerator
(加上通用双胞胎,尽管事实上很少有人需要针对
IEnumerator
)编写代码

如果你想进入任何一个领域,你会很快遇到更多的人——比如数据访问的
IDbCommand
/
IDataReader
等等——但重要的不仅仅是接口。像
Stream
这样的东西是一个类(虽然是抽象的),但是非常重要


我认为一个更好的问题/策略可能是“考虑到我正在做[特定X],需要了解哪些重要类型?”。因为我们不知道[specific X],所以无法回答那么多问题。

这里是一个.NET Framework类库文档

通过单击选定的名称空间,您将看到在该名称空间中定义的接口。
在我拙劣的见解中,这种分类列表用作参考比简单的接口列表要舒服得多。

下面是一些获取接口集合的LINQ,其中“文件”是要搜索的库数组

   var interfaces = (from fileName in files
                     select Assembly.LoadFile(fileName)
                     into assembly
                     select assembly.GetTypes()
                     into typesInAssembly
                     from interfacesInType in typesInAssembly.Select(type => type.GetInterfaces())
                     from interfaceInType in interfacesInType
                     select interfaceInType)
                     .Distinct()
                     .OrderBy( i => i.Name);

很好的建议,但是我认为有一些东西可以说,关于能够探索一点,看看框架有什么在商店里。例如,永远不知道何时需要自定义可恢复的更改跟踪。()
   var interfaces = (from fileName in files
                     select Assembly.LoadFile(fileName)
                     into assembly
                     select assembly.GetTypes()
                     into typesInAssembly
                     from interfacesInType in typesInAssembly.Select(type => type.GetInterfaces())
                     from interfaceInType in interfacesInType
                     select interfaceInType)
                     .Distinct()
                     .OrderBy( i => i.Name);