防止财产被序列化 [英] Prevent Property from being serialized

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

问题描述

我尝试过这样的事情:

    [NonSerialized]
    private string _DecodeText;
    public string DecodeText { get { return _DecodeText; } set { _DecodeText = value; } }

但是它不起作用."DecodeText"仍在序列化文件中.如何防止媒体资源序列化?

But it does not work. "DecodeText" is still in the serialized file. How can i prevent the property from serializing?

推荐答案

我怀疑您正在使用 XmlSerializer ?如果是这样,请改用 [XmlIgnore] 属性.

I Suspect you're using the XmlSerializer? If so use the [XmlIgnore] attribute instead.

这应该应用于属性而不是背景字段,因为 XmlSerializer 会序列化公共字段和属性(而BinaryFormatter使用refelction来获取私有字段-因此私有字段的标记使用BinaryFormatter时使用NonSerialized.

This should be applied to the property instead of the backing field as the XmlSerializer serializes public fields and properties (whereas the BinaryFormatter uses refelction to get at the private fields - hence the marking of the private field with NonSerialized when using a BinaryFormatter).

这篇关于防止财产被序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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