1     /// <summary>

 2     /// Returns all types in the current AppDomain implementing the interface or inheriting the type. 

 3     /// </summary>

 4     public static IEnumerable<Type> TypesImplementingInterface(Type desiredType)

 5     {

 6         return AppDomain

 7             .CurrentDomain

 8             .GetAssemblies()

 9             .SelectMany(assembly => assembly.GetTypes())

10             .Where(type => desiredType.IsAssignableFrom(type));

11 

12     }


    public static bool IsRealClass(Type testType)

    {

        return testType.IsAbstract == false

            && testType.IsGenericTypeDefinition == false

            && testType.IsInterface == false;

    }


作者:KKcat