使用泛型和动态属性。
示例代码:
public class Entity
public Entity()
{
properties = new Dictionary();
}
public T this[string propertyName]
{
get
{
if (properties.ContainsKey(propertyName))
{
return properties[propertyName] as T;
}
return null;
}
set
{
properties[propertyName] = value;
}
}
}
// 使用示例
Entity
上一篇:编译时引用类型相等
下一篇:编译时已知参数的纯虚函数?