Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » XML » Serializing » Downloads
 
Add your own
alternative version

Yet Another XML Serialization Library for the .NET Framework

, 2 Oct 2012 MIT
A flexible XML serialization library that lets developers design the XML file structure, and select the exception handling policy. YAXLib supports polymorphic serialization and serializing generic and non-generic collection classes and arrays.
YAXLib-src-1.1.zip
YAXLib
DemoApplication
Properties
Settings.settings
SampleClasses
YAXLib
Properties
YAXLib-src-1.zip
Settings.settings
YAXLib-src-1_1.zip
Settings.settings
YAXLib-src-2.0.zip
Settings.settings
LocalTestRun.testrunconfig
YAXLib.vsmdi
YAXLibTests
Properties
Test References
// Copyright 2009 - 2010 Sina Iravanian - <sina@sinairv.com>
//
// This source file(s) may be redistributed, altered and customized
// by any means PROVIDING the authors name and all copyright
// notices remain intact.
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED. USE IT AT YOUR OWN RISK. THE AUTHOR ACCEPTS NO
// LIABILITY FOR ANY DATA DAMAGE/LOSS THAT THIS PRODUCT MAY CAUSE.
//-----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

namespace YAXLib
{
    /// <summary>
    /// Holds list of exception occured during serialization/deserialization.
    /// </summary>
    public class YAXParsingErrors
    {
        #region Fields

        /// <summary>
        /// The list of exception occured during serialization/deserialization.
        /// </summary>
        private List<KeyValuePair<YAXException, YAXExceptionTypes>> listExceptions = new List<KeyValuePair<YAXException, YAXExceptionTypes>>();

        #endregion

        #region Properties

        /// <summary>
        /// Gets a value indicating whether the list of errors is empty or not.
        /// </summary>
        /// <value><c>true</c> if the list is not empty; otherwise, <c>false</c>.</value>
        public bool ContainsAnyError
        {
            get
            {
                return this.listExceptions.Count > 0;
            }
        }

        /// <summary>
        /// Gets the number of errors within the list of errors.
        /// </summary>
        /// <value>the number of errors within the list of errors.</value>
        public int Count
        {
            get
            {
                return this.listExceptions.Count;
            }
        }

        #endregion

        #region Indexers

        /// <summary>
        /// Gets the the pair of Exception and its corresponding exception-type with the specified n.
        /// </summary>
        /// <param name="n">The index of the exception/exception type pair in the error list to return.</param>
        /// <value></value>
        public KeyValuePair<YAXException, YAXExceptionTypes> this[int n]
        {
            get
            {
                return this.listExceptions[n];
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Adds an exception with the corresponding type.
        /// </summary>
        /// <param name="exception">The exception to add.</param>
        /// <param name="exceptionType">Type of the exception added.</param>
        public void AddException(YAXException exception, YAXExceptionTypes exceptionType)
        {
            this.listExceptions.Add(new KeyValuePair<YAXException, YAXExceptionTypes>(exception, exceptionType));
        }

        /// <summary>
        /// Clears the list of errors.
        /// </summary>
        public void ClearErrors()
        {
            this.listExceptions.Clear();
        }

        /// <summary>
        /// Adds the list of errors within another instance of <c>YAXParsingErrors</c>.
        /// </summary>
        /// <param name="parsingErrors">The parsing errors to add its content.</param>
        public void AddRange(YAXParsingErrors parsingErrors)
        {
            parsingErrors.listExceptions.ForEach(this.listExceptions.Add);
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            this.listExceptions.ForEach(pair =>
            {
                sb.AppendLine(String.Format(CultureInfo.CurrentCulture, "{0,-8} : {1}", pair.Value, pair.Key.Message));
                sb.AppendLine();
            });

            return sb.ToString();
        }

        #endregion
    }
}

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 MIT License

Share

About the Author

Sina Iravanian
Software Developer
Australia Australia
A software designer and developer
Follow on   Twitter   Google+

| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 2 Oct 2012
Article Copyright 2009 by Sina Iravanian
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid