デザインを変えたほうがいいと思います。抽象ファクトリ パターンを使用できます。リフレクションを使用すると、パフォーマンスが低下します。
これが工場のコードです。
public abstract class MyStore {
public abstract string Name { get; }
public abstract void AddItem(int id, string name);
}
抽象クラスにコードがない場合は、インターフェイスの使用を検討できます。
次に、顧客ストアを作成します。
public class CustomerStore : MyStore, IEnumerable<Customer> {
List<Customer> list = new List<Customer>();
public override string Name { get { return "Customer Store"; } }
public override void AddItem(int id, string name) {
list.Add(new Customer(id, name));
}
public IEnumerator<Customer> GetEnumerator() {
return list.GetEnumerator();
}
}
使用法
foreach (MyStore store in List<MyStore>)
store.AddItem(0, "None");
店舗のタイプを検討したい場合は、
switch (store.Name) {
case "Customer Store":
SomeMethod((CustomerStore)store);
break;
default:
throw new WhatEverException();
}