473,666 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Serialization

Val
I have a complex object that I need to serialize. Rather than rely on a
standard routine, which is called during the serialization/deserialization , I
would like to be able to use my own functions that would convert this object
into a string and would then write that string to a file. Upon
deserialization , I need to be able to call another custom function to
recreate the object.

I have looked and both implementing the ISerializable Interface and at using
the On(De)serializi ng(ed) Attributes, but the only seem to set particular
fields of the object without dealing with particular fields of the object
without allowing me to record/recreate object as a whole.

Thanks

Sep 21 '06 #1
4 6444
For this, you should not be using serialization. What you really want
to do is implement a TypeConverter which will convert your object to a
string.

The serialization framework is meant to abstract the serialization
process in the sense that you won't have to worry about formatting, you just
have to worry about what gets serialized. You could always implement
ISerializable and then set one field which is the string which really
repreents your objects, but that just doesn't seem right.

Here is a link that I found from google with the search phrase
"implementi ng a TypeConverter":

http://www.codeguru.com/columns/vb/article.php/c6529/

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Val" <Va*@discussion s.microsoft.com wrote in message
news:A9******** *************** ***********@mic rosoft.com...
>I have a complex object that I need to serialize. Rather than rely on a
standard routine, which is called during the
serialization/deserialization , I
would like to be able to use my own functions that would convert this
object
into a string and would then write that string to a file. Upon
deserialization , I need to be able to call another custom function to
recreate the object.

I have looked and both implementing the ISerializable Interface and at
using
the On(De)serializi ng(ed) Attributes, but the only seem to set particular
fields of the object without dealing with particular fields of the object
without allowing me to record/recreate object as a whole.

Thanks

Sep 21 '06 #2
Val
Well... This is not the only object i am serializing, but the slowest one to
do so. That is why i wanted to use the custom routine just for it and leave
the other objects to the system.

Do you have any suggestions on how to do it?

Thanks

"Nicholas Paldino [.NET/C# MVP]" wrote:
For this, you should not be using serialization. What you really want
to do is implement a TypeConverter which will convert your object to a
string.

The serialization framework is meant to abstract the serialization
process in the sense that you won't have to worry about formatting, you just
have to worry about what gets serialized. You could always implement
ISerializable and then set one field which is the string which really
repreents your objects, but that just doesn't seem right.

Here is a link that I found from google with the search phrase
"implementi ng a TypeConverter":

http://www.codeguru.com/columns/vb/article.php/c6529/

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Val" <Va*@discussion s.microsoft.com wrote in message
news:A9******** *************** ***********@mic rosoft.com...
I have a complex object that I need to serialize. Rather than rely on a
standard routine, which is called during the
serialization/deserialization , I
would like to be able to use my own functions that would convert this
object
into a string and would then write that string to a file. Upon
deserialization , I need to be able to call another custom function to
recreate the object.

I have looked and both implementing the ISerializable Interface and at
using
the On(De)serializi ng(ed) Attributes, but the only seem to set particular
fields of the object without dealing with particular fields of the object
without allowing me to record/recreate object as a whole.

Thanks


Sep 21 '06 #3
Val,

My guess is that a custom routine isn't going to help much. The first
thing you should do is see how much data you are actually serializing, and
determine how much of it you need to save. Encoding that data into a
string, or a byte array is still going to be relative to the amount of data
you need to store.

Granted, there is an overhead with serialization, in that it uses
reflection to get field names and whatnot, and a custom implementation of
serialization will help to reduce that overhead.

I would recommend looking at the size of the object first, and what you
are serializing. See if you can't bring that set of data down. Then, look
at encoding formats.

To give you a real world example, the DataSet by default serializes its
members by creating an XML representation internally and then storing that
in the custom implementation of ISerializable. In .NET 2.0, a binary
formatting option was offered which was MUCH, MUCH faster.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Val" <Va*@discussion s.microsoft.com wrote in message
news:CB******** *************** ***********@mic rosoft.com...
Well... This is not the only object i am serializing, but the slowest one
to
do so. That is why i wanted to use the custom routine just for it and
leave
the other objects to the system.

Do you have any suggestions on how to do it?

Thanks

"Nicholas Paldino [.NET/C# MVP]" wrote:
> For this, you should not be using serialization. What you really
want
to do is implement a TypeConverter which will convert your object to a
string.

The serialization framework is meant to abstract the serialization
process in the sense that you won't have to worry about formatting, you
just
have to worry about what gets serialized. You could always implement
ISerializabl e and then set one field which is the string which really
repreents your objects, but that just doesn't seem right.

Here is a link that I found from google with the search phrase
"implementin g a TypeConverter":

http://www.codeguru.com/columns/vb/article.php/c6529/

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Val" <Va*@discussion s.microsoft.com wrote in message
news:A9******* *************** ************@mi crosoft.com...
>I have a complex object that I need to serialize. Rather than rely on a
standard routine, which is called during the
serialization/deserialization , I
would like to be able to use my own functions that would convert this
object
into a string and would then write that string to a file. Upon
deserialization , I need to be able to call another custom function to
recreate the object.

I have looked and both implementing the ISerializable Interface and at
using
the On(De)serializi ng(ed) Attributes, but the only seem to set
particular
fields of the object without dealing with particular fields of the
object
without allowing me to record/recreate object as a whole.

Thanks



Sep 21 '06 #4
Val <Va*@discussion s.microsoft.com wrote:
Well... This is not the only object i am serializing, but the slowest one to
do so. That is why i wanted to use the custom routine just for it and leave
the other objects to the system.

Do you have any suggestions on how to do it?
Implement ISerializable and create the required constructor. Construct the
string that you want serialized from the instance data and store it in a named
parameter like usual ... rather than storing the instance values into named
parameters. In the constructor, deserialize the string, break it appart and
reset the instance variables.
[Serializable]
public class TestSerializabl eClass : ISerializable
{
private int i = 0;
private int j = 0;

public TestSerializabl eClass()
{

}

public TestSerializabl eClass(Serializ ationInfo info,
StreamingContex t context)
{
string serialString = info.GetString( @"DATA");

i = Convert.ToInt32 (serialString.S plit('-')[0]);
j = Convert.ToInt32 (serialString.S plit('-')[1]);
}

#region ISerializable Members

public void GetObjectData(S erializationInf o info,
StreamingContex t context)
{
string serialString = string.Format(" {0}-{1}", i, j);

info.AddValue(@ "DATA", serialString);
}

#endregion
}
Hope this helps.

--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1
Sep 21 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2338
by: psy000 | last post by:
Hi, I have a C# web service client that talks to a JAVA application sever. I use AXIS to generate the WSDL file, use wsdl.exe to generate proxy stub c# code. When I try to use c# client connect to application server, I did not get the result in the C# client side, I used a soap monitor to look at the SOAP messages that were exchanged, I can see server returned a correct SOAP message, but the C# client failed to deserialize the XML...
8
6006
by: Joe | last post by:
I have several classes which I need serialized. Here is their class definitions: public class TopContainer { private LevelTwoType m_levelTwo; public LevelTwoType LevelTwo { get {
1
7269
by: Knecke | last post by:
Hi all. I have a problem with returning a custom Result object with webservice. The classes i use is described below (some fields and properties is removed) public class Result { int statusCode;
1
1589
by: leodippolito | last post by:
Dear sirs, I am using custom wrappers to primitive types in my classes, so I can have some flags when working with the database ("undefined" and "null") .. So instead of: public class User
5
16538
by: Mountain | last post by:
I'm working with the example code found at http://msdn2.microsoft.com/en-us/library/system.configuration.applicationsettingsbase(VS.80).aspx. I would like to implement application settings based on some custom types. For example, let's say I have a collection of settings that I could represent similar to this code: public class MyItem {
0
1418
by: Michael Primeaux | last post by:
Please maximize for easier viewing. I'm using XSD.EXE to generate a .CS class. I've added my own attributes to the .XSD file and would like to override the SchemaImporterExtension.ImportSchemaType method to add my own custom attributes to the generated classes. For example, let's assume XSD.EXE generates a class similar to the following:
3
2636
by: Zachary Turner | last post by:
Hello, I have a situation where I would like to perform custom serialization and deserialization of an existing .NET framework object (specifically, System.DateTime). Is there a common paradigm here, for how I can override the default behavior of DateTime serialization and provide my own? I want to use this custom serialized DateTime in many places, and don't want to provide custom serialization routines for every single object that...
4
5822
by: ThunderMusic | last post by:
Hi, I have a custom form that works fine when I debug it or run it in release mode but cannot be loaded in the designer... Actually, it can be loaded in the designer when no control is on it, but the resizing tool (in the designer) is offset both horizontally and vertically and when I put a control on it, as soon as I save, the designer throws an exception (but cannot be reproduced everytime) and the form cannot be loaded anymore unless...
11
10127
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I have worked with application settings in VS2005 and C# for awhile, but usually with standard types. I have been trying to store a custom container/class/type in an application setting and I have seen erratic results. I am aware of one known defect where user classes do not show up in the list of types on the Property/Settings page in the visual designer and I am wondering if I am encountering some other peculiar issue, or if there are...
0
8352
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7378
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6189
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.