.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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
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: 4 stars4 stars4 stars4 stars4 stars / 4
    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
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    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

    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries
    - Introducing LINQ to SQL Designer using Visua...
    - Beginning LINQ to SQL Using Visual Studio 20...
    - Coding an AjaxPro.NET Based Search Engine fo...
    - Building an AjaxPro.NET Based Search Engine ...
    - Delving Deeper into Serialization with .NET
    - Serialization with .NET
    - Understanding Interface-Based Programming
    - Generics and Interface-Based Programming
    - Delving Deeper into Interface-Based Programm...
    - Interface-Based Programming
    - The Why and How of the SplitContainer Control
    - Building an ASP.NET 2.0 Master Page in Three...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway