Click here to Skip to main content
15,893,668 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.Reflection
Imports Microsoft.VisualBasic


''' <summary>
''' Manages all exceptions thrown by serialization.
''' </summary>
Public Class XmlSerializationException
    Inherits ApplicationException
#Region "Constructors"

    ''' <summary>
    ''' Constructor.
    ''' </summary>
    ''' <param name="data">data that causes the error.</param>
    ''' <param name="serializableData">SerializableData associated to error.</param>
    Public Sub New(ByVal data As Object, ByVal serializableData As SerializableData)
        _data = data
        _serializableData = serializableData
    End Sub

    ''' <summary>
    ''' Constructor.
    ''' </summary>
    ''' <param name="data">data that causes the error.</param>
    ''' <param name="serializableData">SerializableData associated to error.</param>
    ''' <param name="propertyInfo">PropertyInfo associated to error.</param>
    ''' <param name="fieldInfo">FieldInfo associated to error.</param>
    Public Sub New(ByVal data As Object, ByVal serializableData As SerializableData, ByVal propertyInfo As PropertyInfo, ByVal fieldInfo As FieldInfo)
        _data = data
        _serializableData = serializableData
        _propertyInfo = propertyInfo
        _fieldInfo = fieldInfo
    End Sub

#End Region

#Region "Properties"

    Private _data As Object = Nothing
    ''' <summary>
    ''' Gets the object that thrown the exception.
    ''' </summary>
    Public ReadOnly Property DataInfo() As Object
        Get
            Return _data
        End Get
    End Property

    Private _serializableData As SerializableData = Nothing
    ''' <summary>
    ''' Gets the SerializableData that thrown the exception.
    ''' </summary>
    Public ReadOnly Property SerializableDataInfo() As SerializableData
        Get
            Return _serializableData
        End Get
    End Property

    Private _propertyInfo As PropertyInfo = Nothing
    ''' <summary>
    ''' Gets the PropertyInfo that can have generated error.
    ''' </summary>
    Public ReadOnly Property [Property]() As PropertyInfo
        Get
            Return _propertyInfo
        End Get
    End Property

    Private _fieldInfo As FieldInfo = Nothing
    ''' <summary>
    ''' Gets the FieldInfo that can have generated error.
    ''' </summary>
    Public ReadOnly Property Field() As FieldInfo
        Get
            Return _fieldInfo
        End Get
    End Property

    ''' <summary>
    ''' Gets the message for the error.
    ''' </summary>
    Public Overloads Overrides ReadOnly Property Message() As String
        Get
            Dim _message As String = MyBase.Message
            _message &= CType(IIf(_data IsNot Nothing, GetFormattedText(Resource.Data) & _data.ToString(), _
                            GetFormattedText(Resource.NoData)), String)
            _message &= CType(IIf(_serializableData IsNot Nothing, GetFormattedText(Resource.SerializableData) & GetFormattedText(Resource.Assembly) & _serializableData.Assembly & GetFormattedText(Resource.AssemblyQualifiedName) & _serializableData.AssemblyQualifiedName & GetFormattedText(Resource.FieldName) & _serializableData.FieldName & GetFormattedText(Resource.TagName) & _serializableData.TagName & GetFormattedText(Resource.Type) & _serializableData.Type & GetFormattedText(Resource.Value) & _serializableData.Value & GetFormattedText(Resource.SerializableDataCollectionCount) & _serializableData.SerializableDataCollection.Count.ToString(), GetFormattedText(Resource.NoSerializableData)), String)

            Dim propertyMessage As String = String.Empty

            If _propertyInfo IsNot Nothing Then
                propertyMessage = Resource.PropertyInfo & " " & _propertyInfo.Name & ": "
                propertyMessage &= CType(IIf(_propertyInfo.CanRead, Resource.Readeable, Resource.NoReadeable & "" & Chr(10) & ""), String)
                propertyMessage &= Resource.PropertyInfo & " " & _propertyInfo.Name & ": "
                propertyMessage &= CType(IIf(_propertyInfo.CanWrite, Resource.Writeable, Resource.NoWriteable & "" & Chr(10) & ""), String)
            End If

            Dim fieldMessage As String = String.Empty

            If _fieldInfo IsNot Nothing Then
                fieldMessage = Resource.FieldInfo & " " & _fieldInfo.Name & ": "
                fieldMessage &= CType(IIf(_fieldInfo.IsLiteral, Resource.Constant, Resource.NoConstant & "" & Chr(10) & ""), String)
            End If

            _message &= propertyMessage & fieldMessage

            Return _message
        End Get
    End Property

#End Region

#Region "Protected Functions"

    ''' <summary>
    ''' Gets formatted text.
    ''' </summary>
    ''' <param name="text">Text to fromat.</param>
    ''' <returns>Formatted text.</returns>
    Protected Function GetFormattedText(ByVal text As String) As String
        Return "" & Chr(10) & "" + text + ": "
    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