[Serializable]
public class foo
{
private int foo;
[NonSerialized]
private byte []bar;
public foo()
{
bar = new byte[128]; // we need to perform this on deserialization too!
}
}
[.net] C# - Instatiation of Non-Serialized objects during Serialization
What you are after is custom deserialization logic in C#. That search will probably lead you to implement ISerializable.
You didn't mention which serializer you are using, if it is the Soap- or BinaryFormatter and not the XmlSerializer, the easiest way would be to mark a method with the OnDeserializedAttribute and initialize your buffer there:
[OnDeserialized]internal void InitFields(StreamingContext context) { bar = new byte[128];}
Quote:Original post by itachi
You didn't mention which serializer you are using, if it is the Soap- or BinaryFormatter and not the XmlSerializer, the easiest way would be to mark a method with the OnDeserializedAttribute and initialize your buffer there:[OnDeserialized]internal void InitFields(StreamingContext context) { bar = new byte[128];}
I am using the BinaryFormatter; and this is eventually how I ended up doing it. :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement