using System.Collections.Generic;
public static void Main()
var fooBars = FooBarizableFactory.GetFooBars(typeof(Foo));
foreach( var fb in fooBars)
Console.WriteLine(fb.GetType());
public abstract class FooBarizable{
public string Name { get; set; }
public class Foo : FooBarizable{
public int FooInt { get; set; }
public class Bar : FooBarizable{
public string BarString { get; set; }
public static class FooBarizableFactory {
public static IEnumerable<FooBarizable> GetFooBars(Type type){
var parentType = typeof(FooBarizable);
if (!parentType.IsAssignableFrom(type))
throw new ArgumentException("Not a FooBarizable");
return new List<Foo>() { new Foo () };
return new List<Bar>() { new Bar() };
throw new ArgumentException("Not a known FooBarizable");