我有一个类:
class MyClass
{
}
...
MyClass c = new MyClass();
是否可以在运行时向此类添加属性/字段?
(我不知道它们在编译时的类型或名称,它们也没有一个我可以使用的公共接口。)
伪代码示例:
Add property named "Prop1" [type System.Int32]
Add property named "Prop900" [type System.String]
我已经阅读了这篇问题,但它使用了接口
提前致谢。
Dictionary<string, object>
怎么样? - H HMyClass.GetType().GetProperties()
访问它们。 - Royi NamirICustomTypeDescriptor
呢? - Dennis