Click here to Skip to main content
12,350,597 members (24,653 online)
Click here to Skip to main content
Articles » Languages » XML » Serializing » Downloads

Stats

195.5K views
269 downloads
205 bookmarked
Posted

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
DemoApplication
Properties
SampleClasses
YAXLib
Properties
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.Linq;
using System.Text;

namespace YAXLib
{
    /// <summary>
    /// Implements a singleton pool of type-wrappers to prevent excessive creation of 
    /// repetetive type wrappers
    /// </summary>
    internal class TypeWrappersPool
    {
        /// <summary>
        /// The instance to the pool, to implement the singleton
        /// </summary>
        private static TypeWrappersPool s_instance = null;

        /// <summary>
        /// A dictionary from types tp their corresponding wrappers
        /// </summary>
        private Dictionary<Type, UdtWrapper> m_dicTypes = new Dictionary<Type, UdtWrapper>();

        /// <summary>
        /// Prevents a default instance of the <c>TypeWrappersPool</c> class from being created, from
        /// outside the scope of this class.
        /// </summary>
        private TypeWrappersPool()
        {
        }

        /// <summary>
        /// Gets the type wrappers pool.
        /// </summary>
        /// <value>The type wrappers pool.</value>
        public static TypeWrappersPool Pool
        {
            get
            {
                if (s_instance == null)
                    s_instance = new TypeWrappersPool();
                return s_instance;
            }
        }

        /// <summary>
        /// Cleans up the pool.
        /// </summary>
        public static void CleanUp()
        {
            if (s_instance != null)
            {
                s_instance = null;
                // TODO: not sure if it's good work to do
                GC.Collect();
            }
        }

        /// <summary>
        /// Gets the type wrapper corresponding to the specified type.
        /// </summary>
        /// <param name="t">The type whose wrapper is needed.</param>
        /// <param name="caller">reference to the serializer instance which called this method.</param>
        /// <returns>the type wrapper corresponding to the specified type</returns>
        public UdtWrapper GetTypeWrapper(Type t, YAXSerializer caller)
        {
            UdtWrapper result;
            if (!m_dicTypes.TryGetValue(t, out result))
            {
                result = new UdtWrapper(t, caller);
                m_dicTypes.Add(t, result);
            }
            else
            {
                result.SetYAXSerializerOptions(caller);
            }

            return result;
        }
    }
}

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

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 2 Oct 2012
Article Copyright 2009 by Sina Iravanian
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid