CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Mar 2009
    Posts
    2

    About attributes

    Hi,

    If i want to serialize an object with a transient member using, for instance, a binary formatter, and "reconstruct" the transient member when i deserialize the object, i've two solutions (as far i know)

    1) using the IDeserializationCallback interface and implementing its OnDeserialization() method:

    Code:
    [Serializable] 
    class Truc : IDeserializationCallback {
    	private int limite;
    	[NonSerialized] 
            private int[] tab;
            (...)
            // Automatically called after Deserialize()
            public virtual void OnDeserialization(Object sender) {
            (...)
            }
    }
    2) throwing away the interface and using the [OnDeserialized] attribute with the OnDeserialized() method:

    Code:
    [Serializable] 
    class Truc : [IDeserializationCallback {
    	private int limite;
    	[NonSerialized] 
            private int[] tab;
            (...)
            [OnDeserialized]
           public void OnDeserialized(StreamingContext context)  {
           (...)
           }
    }
    Both give the same result : the tab member is not serialized and is reconstructed after deserialization.

    But i wonder if there is, somewhere, guidelines about which is the better way (for my own, i think the second is "cleaner", but it's purely subjective...)
    Last edited by Davenull; March 23rd, 2009 at 06:30 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured