我想执行以下操作,但是我不知道如何声明ObservableCollection
class SomeClass
{
SomeClass(PropertyInfo prop)
{
Type detailTyp = prop.GetType();
ObservableCollection<???> col;
//ObservableCollection<detailTyp> col; doesn't work, 'detailTyp' is a variable but used like a Type
if (detailTyp.Name == "a")
{//detailTyp can only return Types that inherit from a certain base class
col = new ObservableCollection<a>();
//If I use ObservableCollection<baseClass>, then I get a conversion error here
}
else if (detailTyp.Name == "b")
{
col = new ObservableCollection<b>();
}
foreach (DataRow row in table.Rows)
{
object o = Activator.CreateInstance(detailTyp());
col.Add(o);
}
}
}