المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Need help w/ custom serialization (specifically OnSerializing attribute)



C# Programming
04-02-2011, 12:41 PM
I have a collection class marked with [Serializable]. Its purpose is "lazy" loading of data. I have overriden all the accessor methods so I can call the item factory to load the item. All works perfect.

A user recently pointed out that if he uses the XML serializer, it doesn't work.

I do have a method thats marked with OnSerialized. Works great with the binary formatter, but doesn't get called with the XML one.

[OnSerialized]
internal void OnSerializing(StreamingContext context)
{
LazyLoad();
}

Whats the work-around to support both? Without a lot of wheel reinvention http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif .