Thank You for the answe! You are right, but I have 2 problems with ISerializable.
1)Serializing with ISerializable is whinchester place wasteful. This is because SerializationInfo.AddValue(string name, object value, Type type) uses possibly different 'name's for every object. I was testing this, and found, that when I used the same name parameter in all the instances of a certain type, the framework intelligently noticed this, and placed the name paramater only in one instance. But, it is not perfect, and if my object graph has even a little complexity, it loses this intelligence. 2)The framework saves the type of all the serialized objects in the form of a string. This string is constructed of the namespace names and the name of the class. I can not specify an alternative name for the framework to use for this purpose. It would be good if for example the SerializableAttribute had such a parameter in its constructor. But it does not have. This involves, that if I want to keep the ability to read in a document that was serialized out with an older version of my application, I may not change the names of my classes during the development, I may not change the names of the namespaces, and I may not put my classes into other namspaces. I think, these are big constraints. ----- Original Message ----- From: "Paul Stevens" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, August 11, 2004 9:55 AM Subject: Re: serialization with varying class schema > ---------------------- Information from the mail header ----------------------- > Sender: "Unmoderated discussion of advanced .NET topics." > <[EMAIL PROTECTED]> > Poster: Paul Stevens <[EMAIL PROTECTED]> > Subject: Re: serialization with varying class schema > -------------------------------------------------------------------------- ----- > > By implementing custom serialisation, you can handle any exceptions that > occur when the class is de-serialized and the class signature has changed= > . > For example, in the overloaded ctor of the class used for custom > de-serialisation the following line would check to see if a value exists = > in > the de-serialised stream, if it does it will assign the value to the obje= > ct, > if not it will create a new instance of the object. > > mRows =3D (info.GetValue("mRows", mRows.GetType())=3D=3Dnull?new > RowDefinitionCollection():(Novasoft.Tomahawk.Base.RowDefinitionCollection= > )in > fo.GetValue("mRows", mRows.GetType())); > > > > -----Original Message----- > From: T=F3th Zolt=E1n [mailto:[EMAIL PROTECTED] > Sent: 05 August 2004 11:29 PM > To: [EMAIL PROTECTED] > Subject: [ADVANCED-DOTNET] serialization with varying class schema > > Hi, > > (Sorry for my bad English) > > I want to develop a windows application (an integrated development > environment). The user should be able to edit the document (his/her > program), save it, open it. Because of the characteristic of the document= > > type, I can not use XML serialization, a textual representation would be > very inefficient. I want to use BinaryFormatter. > > The schema of the document will be quit complex, many classes and many > data-fields in the classes. The difficulty is that the data-fields of any= > > class are not exactly known yet. I will have to add new fields to a class= > > (and delete existing ones) during the development. For example: > Suppose I represent the if ... then ... else ... program structure with > > class If > { > =20 BoolExpression Condition; > =20 Block IfTrue; > =20 Block IfFalse; > } > > the application is ready, works. I edit a 'program' with it. Then I decid= > e > to add a new field: > > class If > { > =20 string Comment; <<<---- > =20 BoolExpression Condition; > =20 Block IfTrue; > =20 Block IfFalse; > } > > to make it possible for the user to attach a comment for his/her If > structure. > Now with the new version of my application I want to open a document that= > > was saved with the previous version of my application. > > Using the built-in .Net serialization mechanism with BinaryFormatter, the= > =201. > error message is about the version mismatch. I could avoid this problem w= > ith > specifying a concrete version writing it into the sourcecode. Now a 2., > bigger problem appeared: for each object Obj the .Net serializes out the > number of member fields of Obj that have to be serialized when serializin= > g > Obj. Because I want to add new fields continuously, this number is varyin= > g. > During deserialization the .Net framework detects this variance and throw= > s > an exception. As the MSDN advises I tried to find a solution with the > ISerializable interface. The problem remained, .Net still serializes the > number of (string, value) pairs that I specify in the function > GetObjectData. > > Because of this difficulty (possibly limit) I developed an own serializat= > ion > mechanism working similarly to .Net (through reflection). This solved my > problem, it works (and also produces smaller files then the built-in > mechanism :-) ). > > I write this letter to ask you: did I really had to develop this own > serialization mechanism or the problem can be solved with the .Net framew= > ork > as well. I ask this because now I decided to review this mechanism, and m= > ake > it much better quality. This would take much time and I do not want to wo= > rk > on it needlessly. > > Zoli > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > This list is hosted by DevelopMentor=AE http://www.develop.com > Some .NET courses you may be interested in: > > Essential .NET: building applications and components with CSharp > August 30 - September 3, in Los Angeles > http://www.develop.com/courses/edotnet > > View archives and manage your subscription(s) at http://discuss.develop.c= > om > *************************************************************************= > ************************************************* > Everything in this e-mail and attachments relating to the official busine= > ss of MultiChoice Africa is proprietary to=20 > the company. Any view or opinion expressed in this message may be the vie= > w of the individual and should not automatically=20 > be ascribed to the company. If you are not the intended recipient, you m= > ay not peruse, use, disseminate, distribute or=20 > copy this message. If you have received this message in error, please not= > ify the sender immediately by email, facsimile=20 > or telephone and destroy the original message. > *************************************************************************= > ************************************************* > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= 3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > This list is hosted by DevelopMentor=AE http://www.develop.com > Some .NET courses you may be interested in: > > Essential .NET: building applications and components with CSharp > August 30 - September 3, in Los Angeles > http://www.develop.com/courses/edotnet > > View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorŽ http://www.develop.com Some .NET courses you may be interested in: Essential .NET: building applications and components with CSharp August 30 - September 3, in Los Angeles http://www.develop.com/courses/edotnet View archives and manage your subscription(s) at http://discuss.develop.com