English 中文(简体)
氧化硫和氧化硫
原标题:XmlSerializer and OnSerializing/OnSerialized alternatives

我有各种复杂的物体,往往收集其他复杂的物体。 有时,我只想在收件重新需要时装货,因此,我需要一种办法,来追踪收件是否被装满(null/empty don t 必然意味着装货吨)。 为了做到这一点,这些复杂的物体继承一批装货集。 然后,我们刚刚需要增加一项呼吁,要求我们按要求进行收集,以便:

public List<ObjectA> ObjectAList {
    get { return _objectAList; }
    set { 
        _objectAList = value; 
        PropertyLoaded("ObjectAList");
    }
}

财产租赁功能更新了一套能够追踪已装载的收集资料。

不幸的是,这些物体被用于网络服务,因此(de)被erial化,所有制片人都被叫来,而实际上 t头时,财产被洗 called。

理想的情况是,我能够使用OnSerializing/OnSerialized,这样就知道其被称作合法,然而我们却使用XmlSerializer,这样就能够从事这项工作。 由于各种原因,我现在可以改变使用数据用户的做法。

是否有其他办法了解是否发生序列化? 如果不每当需要跟踪新的收集工作时,就不必增加编码,那么能否实现上述目标?

问题回答

<代码>XmlSerializer不支持序列化呼退。 不过,你有一些选择。 例如,如果你想选择是否将称作<条码>的不动产序列化,你可以添加一种方法:

public bool ShouldSerializeObjectAList () { /* logic */ }

如果你也需要在帝国化过程中知道,你可以使用:

[XmlIgnore]
public bool ObjectAListSpecified {
    get { /* logic whether to include it in serialization */ }
    set { /* logic to apply during deserialization */ }
}

(尽管你可能发现——我可以肯定——“<条码><>/条码>只要求<条码><>true> 例”)

当然,另一个选择是执行<代码>IXmlSerializable,但这只应作为最后的手段。 它是t fun。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签