Google+ Tools
Make Google+ profile picture
Make Google plus banners for profile
Create and share your Google Plus profile banners.

Profile image for mrk studios Stephen Smith on March 4, 2010
Code iterates over a list of assemblies (see snippet http://www.codekeep.net/members/snippetedit.aspx?id=17665) looking for descendants of a particular type and with an empty constructor.
Language
C#
Tags

Get a list of types that are derived from a particular base class or interface.


private static IList<Type> GetTypesInAssembly<T>() where T : class
{
    List<Type> result = new List<Type>();

    foreach (Assembly assembly in Assemblies)
    {
        Type[] types = assembly.GetTypes();

        foreach (Type type in types)
        {
            if (type.IsAbstract || type.IsInterface) continue; // ignore abstract and interfaces.

            if (typeof(T).IsAssignableFrom(type) && // is of the correct type
                type.GetConstructor(new Type[] { }) != null)  // and has an empty ctor.
            {
                result.Add(type);
            }
        }
    }
    return result;
}

Comments

blog comments powered by Disqus