在运行时更改类定义 [英] Change class definition on runtime
本文介绍了在运行时更改类定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,伙计们, 我在想,如果有一种方法为我改变的属性一类有(添加/删除属性)上运行。
Hey guys, I was wondering if there is a way for me to change the properties a class has (add/remove properties) on runtime..
这可能吗?
推荐答案
您不能,除非你正在使用的<一个实例做href="http://msdn.microsoft.com/en-us/library/system.dynamic.expandoobject.aspx"><$c$c>ExpandoObject$c$c>.对于一个CLR类型的元数据是固定的,在装配和不能在执行时发生变化。如果你真的需要这种动态行为,你必须使用动态类型(如 EpandoObject
),支持这种行为。
You cannot do this unless you are working with an instance of ExpandoObject
. The metadata for a CLR type is fixed in the assembly and cannot be changed at execution time. If you really need this kind of dynamic behavior you must use a dynamic type (like EpandoObject
) that supports this behavior.
这篇关于在运行时更改类定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文