序列化类中的Type属性 [英] Serialize a Type property in a class

查看:291
本文介绍了序列化类中的Type属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我的课程如下



Hi

I have a class as follows

[Serializable]
public class test
{
    public string Name { get; set; }
    public Type LocalType { get; set; }
}





当我尝试序列化这个类时它会给出异常



System.RuntimeType由于其保护级别而无法访问。只能处理公共类型。有什么我缺少的或只是Type属性无法序列化吗?



提前谢谢。



When I try to serialize this class it gives the exception

"System.RuntimeType is inaccessible due to its protection level. Only public types can be processed." Is there anything i'm missing or is it just that Type property cannot be serialized?

Thanks in advance.

推荐答案

也许这会对你有所帮助。

http://stackoverflow.com/questions/12306/can-i-serialize-ac-sharp-type-object [ ^ ]
Maybe this helps you.
http://stackoverflow.com/questions/12306/can-i-serialize-a-c-sharp-type-object[^]


您的LocalType成员正在返回一个系统。类型。该类型System.Type部分使用System.RuntimeType实现。这反过来又不公开。因此,LocalType属性无法序列化。



将LocalType标记为[XmlIgnore]或将其更改为可序列化的内容。
Your "LocalType" member is returning a System.Type. That type, System.Type, is implemented, in part, with System.RuntimeType. Which in turn is not public. Therefore, the "LocalType" property cannot be serialized.

Either mark "LocalType" as [XmlIgnore] or change it to something that can be serialized.


这篇关于序列化类中的Type属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆