我有一个类:如何在C#中将运行时属性添加到类中?
class MyClass
{
}
...
MyClass c = new MyClass();
是否有可能将属性/字段添加到这个类在运行时?
(我不知道他们有什么类型或编译时的名字和他们没有共同的界面,我可以使用)。
伪例如:
Add property named "Prop1" [type System.Int32]
Add property named "Prop900" [type System.String]
我已经阅读this question,但它使用接口
在此先感谢。
然后通过反射来访问它们到处?如何处理'Dictionary'? –
@HenkHolterman是的Henk后来我用'MyClass.GetType()来访问它们。GetProperties()' –
你需要什么样的用例?那么'ICustomeTypeDescriptor'呢? – Dennis