From the objects that specify the XML to get a string of the form. - CSharp System.Xml.Serialization

CSharp examples for System.Xml.Serialization:XmlSerializer

Description

From the objects that specify the XML to get a string of the form.

Demo Code


using System.Xml.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System.IO;//from   w w  w . j  ava2 s . c om
using System.Globalization;
using System.Collections.Generic;
using System;

public class Main{
        /// <summary>
        /// From the objects that specify the XML to get a string of the form.
        /// </summary>
        /// <param name="inObject"></param>
        /// <returns></returns>
        public static String ToXml(Object inObject)
        {
            var sl = new XmlSerializer(inObject.GetType());
            var sb = new StringBuilder();
            var sw = new StringWriter(sb);

            sl.Serialize(sw, inObject);
            return sb.ToString();
        }
        /// <summary>
        /// To retrieve the string. If the NULL will return an empty string.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static String ToString(Object value)
        {
            return ToStringOrEmpty(value);
        }
}

Related Tutorials