其中.NET框架类实现IDisposable [英] Which .NET Framework classes implement IDisposable

查看:120
本文介绍了其中.NET框架类实现IDisposable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来这在某处被记录在案,但我没有找到任何想去的地方。也许我的谷歌福正在减弱。

Seems like this has to be documented somewhere but I'm not finding is anywhere. Perhaps my Google-fu is weakening.

推荐答案

您意识到,这将取决于你所说的 .NET Framework类的。你可能会想要指定哪些程序集你正在寻找。有了这些信息,你可以加载这些组件和使用反射来列出实现IDisposable在一个给定的程序集中的所有公共类型。让我们的系统组件,例如:

You realize that this will depend on what you call .NET Framework classes. You probably might want to specify which assemblies you are looking for. Armed with this information you can load those assemblies and use reflection to list all public types that implement IDisposable in a given assembly. Let's take the System assembly as example:

class Program
{
    static void Main()
    {
        var types = Assembly
            .Load("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
            .GetTypes()
            .Where(t => typeof(IDisposable).IsAssignableFrom(t))
            .OrderBy(t => t.Name);
        foreach (var type in types)
        {
            Console.WriteLine(type);
        }
    }
}

这篇关于其中.NET框架类实现IDisposable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆