472,364 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

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)serializing(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 6364
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
"implementing a TypeConverter":

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

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

"Val" <Va*@discussions.microsoft.comwrote in message
news:A9**********************************@microsof t.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)serializing(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
"implementing a TypeConverter":

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

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

"Val" <Va*@discussions.microsoft.comwrote in message
news:A9**********************************@microsof t.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)serializing(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.com
"Val" <Va*@discussions.microsoft.comwrote in message
news:CB**********************************@microsof t.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
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
"implementing a TypeConverter":

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

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

"Val" <Va*@discussions.microsoft.comwrote in message
news:A9**********************************@microso ft.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)serializing(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*@discussions.microsoft.comwrote:
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 TestSerializableClass : ISerializable
{
private int i = 0;
private int j = 0;

public TestSerializableClass()
{

}

public TestSerializableClass(SerializationInfo info,
StreamingContext context)
{
string serialString = info.GetString(@"DATA");

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

#region ISerializable Members

public void GetObjectData(SerializationInfo info,
StreamingContext 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
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...
8
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
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...
1
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...
5
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...
0
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...
3
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...
4
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...
11
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...

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.