.Net Find all objects in current domain that implement IDisposable

using System;
using System.Linq;

namespace CsharpListInterfaceUsage
{
    class InterfaceListerDemo
    {
        public static void Main()
        {
            var interfaceType = typeof(IDisposable);

            var results = AppDomain.CurrentDomain
                                      .GetAssemblies()
                                      .SelectMany(x => x.GetTypes())
                                      .Where(interfaceType.IsAssignableFrom)
                                      .ToList();

            results.ForEach(Print);

            Console.ReadKey();
        }

        private static void Print(Type type)
        {
            Console.WriteLine(type.FullName);
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *