Click here to Skip to main content
15,897,187 members
Articles / Programming Languages / XML

Yet Another XML Serialization Library for the .NET Framework

Rate me:
Please Sign up or sign in to vote.
4.92/5 (91 votes)
2 Oct 2012MIT24 min read 517.8K   207  
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.
// 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.Linq;
using System.Text;
using System.Xml.Linq;

namespace YAXLib
{
    /// <summary>
    /// Provides deserializer methods for some known .NET built-in types.
    /// </summary>
    internal class KnownDotNetTypesDeserializers
    {
        /// <summary>
        /// Deserializes an object of type <c>TimeSpan</c>.
        /// </summary>
        /// <param name="baseElement">The XML element containing serialized <c>TimeSpan</c>.</param>
        /// <returns>deserialized <c>TimeSpan</c> object.</returns>
        public static object DeserializeTimeSpan(XElement baseElement)
        {
            string strTicks = baseElement.Element("Ticks").Value;
            long ticks = 0L;
            if (Int64.TryParse(strTicks, out ticks))
            {
                return new TimeSpan(ticks);
            }
            return null;
        }

        /// <summary>
        /// Deserializes an object of type <c>GUID</c>.
        /// </summary>
        /// <param name="baseElement">The XML element containing serialized <c>GUID</c>.</param>
        /// <returns>deserialized <c>GUID</c> object</returns>
        internal static object DeserializeGuid(XElement baseElement)
        {
            string strGuidValue = baseElement.Value;
            Guid g = new Guid(strGuidValue);
            return g;
        }
    }
}

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


Written By
Software Developer
Australia Australia
A software designer and developer

Comments and Discussions