Binary Serializer : Serialization « File Stream « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » File Stream » SerializationScreenshots 
Binary Serializer
        
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

public static class BinarySerializer
{
    public static void Serialize(Stream stream, object value)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        formatter.Serialize(stream, value);
    }

    public static void Serialize(FileInfo file, object value)
    {
        FileStream stream = null;
        try
        {
            stream = File.Create(file.FullName);
            Serialize(stream, value);
        }
        finally
        {
            if (stream != null)
            {
                stream.Close();
                stream.Dispose();
            }
        }
    }
    public static object Deserialize(Stream stream)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        return formatter.Deserialize(stream);
    }

    public static object Deserialize(FileInfo file)
    {
        FileStream stream = null;
        try
        {
            stream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read);
            return Deserialize(stream);
        }
        finally
        {
            if (stream != null)
            {
                stream.Close();
                stream.Dispose();
            }
        }
    }
}

   
    
    
    
    
    
    
    
  
Related examples in the same category
1.Use Serializable attribute to mark a generic class
2.Use Serializable attribute to mark a class
3.Deserialize Object
4.Serialize and DeSerialize
5.Three types of Serialization: Binary, Soap, XML
6.Use XML Serialization with Custom ObjectsUse XML Serialization with Custom Objects
7.Working with the Serializable Attribute
8.NonSerialized attributesNonSerialized attributes
9.Serialize hiearchy classesSerialize hiearchy classes
10.C# Serialization C# Serialization
11.Serial Employee class
12.Set XML tag name for Serialization
13.illustrates binary serializationillustrates binary serialization
14.Deserialize
15.Collection Serialization
16.Serializes an object to binary
17.Deserializes an object from binary
18.Object to string serialization/Deserialization
19.Object to byte array serialization/Deserialization
20.Javascript Serializer
21.Serialize and Deserialize (2)
22.Deserialize the incomming data to the T datatype, this method used to deserialize the test cases data to the required entity
23.Serialization Utility
24.Serialization Utilities
25.Clone With Serialization
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.