📅  最后修改于: 2022-03-11 14:48:40.109000             🧑  作者: Mango
public abstract class MyClass
{
public abstract Type Type { get; }
}
public class MyClass : MyClass
{
public override Type Type
{
get { return typeof(T); }
}
public T Value { get; set; }
}
// VERY basic illustration of how you might construct a collection
// of MyClass objects.
public class MyClassCollection
{
private Dictionary _dictionary;
public MyClassCollection()
{
_dictionary = new Dictionary();
}
public void Put(MyClass item)
{
_dictionary[typeof(T)] = item;
}
public MyClass Get()
{
return _dictionary[typeof(T)] as MyClass;
}
}