public static string SerializeObject(Object _Object, System.Type _Type, Encoding _EncType) { if (_EncType.EncodingName.ToLower().Contains("utf-8")) { return(SerializeObject(_Object, _Type)); } if (_EncType.EncodingName.ToLower() == "unicode")//== utf-16 but { XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); string XmlizedString = null; MemoryStream memoryStream = new MemoryStream(); XmlSerializer xs = new XmlSerializer(_Type); XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.Unicode); xmlTextWriter.Formatting = Formatting.Indented; xs.Serialize(xmlTextWriter, _Object, ns); memoryStream = (MemoryStream)xmlTextWriter.BaseStream; XmlizedString = XMLSupport.UnicodeByteArrayToString(memoryStream.ToArray()); return(XmlizedString); } else { return("<?xml encoding=\"not_provided\"?>"); } }
public static Object DeserializeObject(string _XMLString, System.Type _Type) { XmlSerializer xs = new XmlSerializer(_Type); MemoryStream memoryStream = new MemoryStream(XMLSupport.StringToUTF8ByteArray(_XMLString)); XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); Object DeserializedObject = xs.Deserialize(memoryStream); return(DeserializedObject); }
public static string SerializeObject(Object _Object, System.Type _Type) { XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); // Disables Microsoft-Specific namespaces of xml-header string XmlizedString = null; MemoryStream memoryStream = new MemoryStream(); XmlSerializer xs = new XmlSerializer(_Type); XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); xmlTextWriter.Formatting = Formatting.Indented; xs.Serialize(xmlTextWriter, _Object, ns); memoryStream = (MemoryStream)xmlTextWriter.BaseStream; XmlizedString = XMLSupport.UTF8ByteArrayToString(memoryStream.ToArray()); return(XmlizedString); }
public static Object DeserializeObject(string _XMLString, System.Type _Type, Encoding _EncType) { if (_EncType.EncodingName.ToLower().Contains("utf-8")) { return(DeserializeObject(_XMLString, _Type)); } if (_EncType.EncodingName.ToLower() == "unicode")//== utf-16 but { XmlSerializer xs = new XmlSerializer(_Type); MemoryStream memoryStream = new MemoryStream(XMLSupport.StringToUnicodeByteArray(_XMLString)); XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.Unicode); Object DeserializedObject = xs.Deserialize(memoryStream); return(DeserializedObject); } else { return(null); } }