.NET
  Home arrow .NET arrow Delving Deeper into Serialization with .NE...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Delving Deeper into Serialization with .NET
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2007-08-15

    Table of Contents:
  • Delving Deeper into Serialization with .NET
  • A Caution on Serialization and Inheritance
  • ISerializable
  • Deserialization

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Delving Deeper into Serialization with .NET


    (Page 1 of 4 )

    In "Serialization with .NET," we began by serializing a simple string. Then, we moved on to serializing custom types and examined how a class can participate in the serialization and deserialization processes using the OnSerializing, OnSerialized, OnDeserializing and OnDeserialized attributes. In this article, we'll continue to examine serialization with .NET.

    Inheritance

    So far, we've only serialized simple classes that don't inherit from anything besides Object. However, it's important to take note of the combination of serialization and inheritance. To experiment, let's create two classes, one of which will inherit from the other. The first will be Shape and will represent any sort of shape. It will have a private field named area with an associated property, Area. The second will be ThreeDimensionalShape and will represent a three-dimensional shape. It will have a private field named volume, with can be accessed through the property Volume. Here are the two classes:

    using System;

     

    public class Shape

    {

       private double area;

       

       public Shape(double area)

       {

           this.area = area;

       }

       

       public double Area

       {

           get

           {

              return area;

           }

       }

    }

     

    public class ThreeDimensionalShape : Shape

    {

       private double volume;

       

       public ThreeDimensionalShape(double area, double volume)

           : base(area)

       {

           this.volume = volume;

       }

       

       public double Volume

       {

           get

           {

              return volume;

           }

       }

    }

    Now, let's apply the Serializable attribute to Shape so that it can be serialized:

    [Serializable]

    public class Shape

    {

       ...

    }

    More .NET Articles
    More By Peyton McCullough


       · Hello, all!In Serialization with .NET, I explained how to use automatic...
     

    .NET ARTICLES

    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek