本文介绍了如何改变运行时类的定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法对我来说,在运行时更改属性一个类(添加/删除属性)?

Is there a way for me to change the properties a class has (add/remove properties) on runtime?

推荐答案

除非你是使用。对于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.

这篇关于如何改变运行时类的定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 17:32