Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 14th, 2007, 10:14 AM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Complex Serialization

Hi All;
I have 3 class, the first class "DataSetClass" has a List<> of 2th class "MyTable" , And 2th has a list<> of 3th class .

i want to serialaization of this object, what shall i do ?

'''''''' Thid is my my code without important property and method ..
[Serializable]
     public class DataSetClass
    {

        public DataSetClass()
        {
        }
         private DataSet dataset = new DataSet();
        [XmlIgnore()]
        [Browsable(false)]
        public DataSet Dataset
         {
             get { return dataset; }
         }

         private List<MyTable> myDataTable;

         public List<MyTable> Tables
         {
             get { return myDataTable; }
             set { myDataTable = value; }
         }

     }
/*************************************************/
 [Serializable]
    public class MyTable
    {
        private DataTable _DataTable = new DataTable();
        public MyTable()
        { }

        private string spName;
        [Category("Setting Store Procedure")]
        public string SpName
        {
            get { return spName; }
            set { spName = value; }
        }


        [XmlArrayItem("Column")]
        List<MyColumn> columns;
        [Category("Table Property")]

        public List<MyColumn> Columns
        {
            get { return columns; }
            set { columns = value; }
        }

    }
/**************************************************/
[Serializable]
    public class MyColumn
    {

        public MyColumn()
        {
    }

        private DataColumn _DataColumn = new DataColumn();

        [XmlIgnore()]
        public DataColumn DataColumn
        {
            get { return _DataColumn; }
            set { _DataColumn = value; }
        }

    }
///////////////////////////////
Thanks in advance.
 
Old April 16th, 2007, 08:37 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Have you tried serializing it? Or are you looking for general code sample on serialization?

http://msdn2.microsoft.com/en-us/lib...erializer.aspx

-Peter
 
Old April 17th, 2007, 12:06 AM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is a complex class to serialization,I want to know comples serialization

 
Old April 17th, 2007, 07:28 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Again, have you tried it? There are thousands of articles and documentation pages on the internet that explain how to do these things. Unless you have tried something already and are having an particular problem, I'm not going to just repeat what is already out there.

There's not anything terribly special about serializing a "complex" object. You serialize it and the serialization logic serializes everything underneath it. There are settings and attributes used to control/change how the serialization behaves. But ultimately, serializing a integer or a large object tree hierarchy amounts to the same thing, a stream of XML.

Please try some things and be more explicit with your questions. We are here to help by providing answers to discreet questions, not to provide complete solutions to vague requests. If you are looking for the latter, please try tutorials or books.

-Peter
 
Old April 18th, 2007, 09:57 AM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Peter ,
i read alot articles and sample about it .
this is my cuestion.
How can i serialize hirerchy class of generic ?

 
Old April 18th, 2007, 10:38 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I think what you need to look into is the serialization attributes that you put on the properties that will be serialized. You have to tell the serializer what types will likely be serialized on a given property. It may very well behave the same way as if you have a property of an Interface type. The interface is not a specific implementation so the serializer can't figure out what class type to instantiate when it encounters the node in the XML. But by defining the possible types, it can determine what type at runtime the instance should be based on the XML.

I haven't done this much myself, but I think what you need to learn about is the XmlIncludeAttribute class. This tells the serializer what types to include in the serialization of the member the attribute is applied to.

http://msdn2.microsoft.com/en-us/lib...attribute.aspx

Take a look at these pages for more:
http://www.topxml.com/xmlserializer/...attributes.asp
http://msdn2.microsoft.com/en-us/library/2baksw0z.aspx

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
serialization taheernawaz ASP.NET 1.x and 2.0 Application Design 0 December 12th, 2007 03:32 AM
Serialization and DeSerialization balesh.mind ASP.NET 2.0 Professional 0 September 12th, 2007 05:05 AM
is serialization required for this? hertendreef ASP.NET 2.0 Basics 0 March 24th, 2007 05:54 AM
question about Serialization hertendreef ASP.NET 2.0 Basics 2 February 27th, 2007 04:03 PM
XML Serialization rajeshnerenki General .NET 0 June 14th, 2004 08:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.