必要なものはFactory Patternと呼ばれます。クラスを使用してクラスを構築し、構築されたものを追跡します。
public class CFactory
{
public CFactory()
{
CreatedCBacking = new List<C>();
}
private List<C> CreatedCBacking;
public IList<C> CreatedC
{
get
{
return CreatedCBacking.AsReadonly();
}
}
public C NewC(String s, string t, bool b)
{
C temp = new C(s, t, b);
CreatedCBacking.Add(temp);
return temp;
}
}
public class C
{
public C(String s, string t, bool b)
{
//You class here
}
}
使い方はこんな感じです
public static void Main()
{
var factory = new CFactory();
var c1 = factory.NewC("string", "string", true);
var c2 = factory.NewC("string2", "string2", false);
foreach(var c in factory.CreatedC)
{
//loops over c1 and c2
}
}