Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# get all classes derived from type

  public static IEnumerable<T> GetEnumerableOfType<T>(Assembly assembly = null, params object[] constructorArgs) where T : class
        {
            List<T> objects = new List<T>();
            foreach (Type type in (assembly ?? Assembly.GetAssembly(typeof(T))).GetTypes()
            .Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(T))))
            {
                objects.Add((T)Activator.CreateInstance(type, constructorArgs));
            }

            return objects;
        }
 
PREVIOUS NEXT
Tagged: #classes #derived #type
ADD COMMENT
Topic
Name
2+1 =