Click here to Skip to main content
15,891,473 members
Articles / Programming Languages / Visual Basic

Mathemathics Framework

Rate me:
Please Sign up or sign in to vote.
4.76/5 (56 votes)
16 Sep 2008CPOL6 min read 75.4K   6.2K   171  
.NET Mathematical Framework
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Reflection
Imports System.Collections.ObjectModel


''' <summary>
''' Manages the serialization of objects.
''' </summary>
Public Class Serializer
#Region "Constructors"

    ''' <summary>
    ''' Default constructor.
    ''' </summary>
    Public Sub New()
    End Sub

#End Region

#Region "Properties"

    Private _serializeWriter As New XmlSerializeWriter()
    ''' <summary>
    ''' Gets or sets the component used to write xml file.
    ''' </summary>
    Public Property SerializeWriter() As XmlSerializeWriter
        Get
            Return _serializeWriter
        End Get
        Set(ByVal value As XmlSerializeWriter)
            _serializeWriter = value
        End Set
    End Property

    Private _serializeReader As New XmlSerializeReader()
    ''' <summary>
    ''' Gets or sets the component used to read xml file.
    ''' </summary>
    Public Property SerializeReader() As XmlSerializeReader
        Get
            Return _serializeReader
        End Get
        Set(ByVal value As XmlSerializeReader)
            _serializeReader = value
        End Set
    End Property

    Private _composer As New SerializableDataComposer()
    ''' <summary>
    ''' Gets or sets the component used to compose a SerialzableData from a serialzable object.
    ''' </summary>
    Public Property Composer() As SerializableDataComposer
        Get
            Return _composer
        End Get
        Set(ByVal value As SerializableDataComposer)
            _composer = value
        End Set
    End Property

    Private _decomposer As New SerializableDataDecomposer()
    ''' <summary>
    ''' Gets or sets the component used to decompose a serialzable object from a SerializableData.
    ''' </summary>
    Public Property Decomposer() As SerializableDataDecomposer
        Get
            Return _decomposer
        End Get
        Set(ByVal value As SerializableDataDecomposer)
            _decomposer = value
        End Set
    End Property

#End Region

#Region "Public Functions"

    ''' <summary>
    ''' Reset serializer state.
    ''' </summary>
    Public Overridable Sub Reset()
        _composer.SerializableDataInfo.Reset()
        _decomposer.SerializableDataInfo.Reset()
        _serializeReader.XmlDocument.RemoveAll()
        _serializeWriter.XmlDocument.RemoveAll()
    End Sub

    ''' <summary>
    ''' Serialize an object.
    ''' </summary>
    ''' <param name="fileName">Filename.</param>
    ''' <param name="data">Data to serialize.</param>
    Public Overridable Sub Serialize(ByVal fileName As String, ByVal data As Object)
        _decomposer.Decompose(data)
        _serializeWriter.WriteXml(fileName, _decomposer.SerializableDataInfo)
    End Sub

    ''' <summary>
    ''' Deserialize an object.
    ''' </summary>
    ''' <param name="fileName">Filename.</param>
    ''' <returns>Deserialized data.</returns>
    Public Overridable Function Deserialize(ByVal fileName As String) As Object
        _serializeReader.ReadXml(fileName, _decomposer.SerializableDataInfo)
        Return _composer.Compose(_decomposer.SerializableDataInfo)
    End Function

#End Region
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer Universidad Tecnológica Nacional
Argentina Argentina
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions