[Unity] C # Tool classes that convert XML and entity classes to each other

Source: Internet
Author: User

Using system;using system.xml;using system.xml.serialization;using system.io;namespace LOTool{public class LO_XMLTool {#region deserialization//<summary>///deserialization///</summary>///<param name= ' type ' > Type </param>///< param name= "xml" >xml string </param>///<returns></returns>public static object Deserialize (Type Type, string xml) {try{using (StringReader sr = new StringReader (XML)) {XmlSerializer xmldes = new XmlSerializer (type); Retu RN Xmldes. Deserialize (SR);}} catch (Exception e) {return null;}} <summary>///deserialization///</summary>///<param name= "type" ></param>///<param name= "xml" ></param>///<returns></returns>public Static Object deserialize (type type, stream stream) { XmlSerializer xmldes = new XmlSerializer (type); return xmldes. Deserialize (stream);} #endregion #region Serialization///<summary>///serialization///</summary>///<param name= "type" > Type </param>/// <param name= "obj" > Object </param>///<reTurns></returns>public static string serializer (type type, Object obj) {MemoryStream Stream = new MemoryStream () ; XmlSerializer XML = new XmlSerializer (type); try{//serializes the object XML. Serialize (Stream, obj);} catch (InvalidOperationException) {throw;} stream.position = 0; StreamReader sr = new StreamReader (Stream); string str = Sr. ReadToEnd (); Sr. Dispose (); Stream.dispose (); return str;} #endregion}}

[Unity] C # Tool classes that convert XML and entity classes to each other

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.