Click here to Skip to main content
15,886,362 members
Articles / Programming Languages / XML

XML Serializer Library

Rate me:
Please Sign up or sign in to vote.
4.92/5 (12 votes)
10 Dec 2007CPOL4 min read 60.3K   1.8K   66  
A library for serializing any class in XML format.
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Reflection;
using System.Collections.ObjectModel;

namespace Globe.Xml.Serialization
{
    /// <summary>
    /// Specified that a class is serializable.
    /// </summary>
    [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
    public class XmlClassSerializable : XmlSerializable
    {
        #region Constructors

        /// <summary>
        /// Default constructor.
        /// </summary>
        public XmlClassSerializable()
        {
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="tagName">Tag name in the xml.</param>
        public XmlClassSerializable(string tagName) : base(tagName)
        {
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="tagName">Tag name in the xml.</param>
        /// <param name="deep">Serialization of all fields hierarchy.</param>
        public XmlClassSerializable(string tagName, bool deep) : base(tagName)
        {
            _deep = deep;
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="tagName">Tag name in the xml.</param>
        /// <param name="deep">Serialization of all fields hierarchy.</param>
        /// <param name="flags">Binding flags.</param>
        public XmlClassSerializable(string tagName, bool deep, BindingFlags flags) : base(tagName)
        {
            _deep = deep;
            _flags = flags;
        }

        #endregion

        #region Properties

        bool _deep = true;
        /// <summary>
        /// Gets if the class must be serialized in the all hierarchy.
        /// </summary>
        public bool Deep
        {
            get { return _deep; }
        }

        BindingFlags _flags = BindingFlags.Default;
        /// <summary>
        /// Gets the binding flags. Some flags will be added by the framework.
        /// </summary>
        public BindingFlags Flags
        {
            get { return _flags; }
        }

        #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 Code Project Open License (CPOL)


Written By
Software Developer
Italy Italy
I am a biomedical engineer. I work in Genoa as software developer. I developed MFC ActiveX controls for industrial automation for 2 years and packages for Visual Studio 2005 for 1 year. Currently I'm working in .NET 3.5 in biomedical area.

Comments and Discussions