/// <summary> /// Deserializes workflow markup into an MyElement object /// </summary> // <param name="xml">string workflow markup to deserialize</param> // <param name="obj">Output MyElement object</param> // <param name="exception">output Exception value if deserialize failed</param> // <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool Deserialize(string xml, out MyElement obj, out System.Exception exception) { exception = null; obj = null; try { System.IO.StringReader stringReader = new System.IO.StringReader(xml); System.Xml.XmlTextReader xmlTextReader = new System.Xml.XmlTextReader(stringReader); System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(MyElement)); obj = ((MyElement)(xmlSerializer.Deserialize(xmlTextReader))); return(true); } catch (System.Exception ex) { exception = ex; return(false); } }
/// <summary> /// Deserializes workflow markup from file into an MyElement object /// </summary> // <param name="xml">string workflow markup to deserialize</param> // <param name="obj">Output MyElement object</param> // <param name="exception">output Exception value if deserialize failed</param> // <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool LoadFromFile(string fileName, out MyElement obj, out System.Exception exception) { exception = null; obj = null; try { System.IO.FileStream file = new System.IO.FileStream(fileName, FileMode.Open, FileAccess.Read); System.IO.StreamReader sr = new System.IO.StreamReader(file); string xmlString = sr.ReadToEnd(); sr.Close(); file.Close(); return(Deserialize(xmlString, out obj, out exception)); } catch (System.Exception ex) { exception = ex; return(false); } }
public void Deserialize_ArrayOfMyElement() { lock (testLock) { var e = new ArrayOfMyElement(); var myE = new MyElement { Name = "Name" }; myE.AttributeLists.Add(new NameValuePair { Name = "Name", Value = "Value" }); e.MyElement.Add(myE); Exception ex; var serialized = e.Serialize(); e.SaveToFile(Path.Combine(OutputFolder, "ReproSampleFile.xml"), out ex); if (ex != null) { throw ex; } //try to deserialize //generate doc conformant to schema ArrayOfMyElement toDeserialize; if (!ArrayOfMyElement.LoadFromFile("ReproSampleFile.xml", out toDeserialize, out ex)) { Console.WriteLine("Unable to deserialize, will exit"); return; } var serialized2 = toDeserialize.Serialize(); Console.WriteLine("Still missing the <NameValuePairElement>"); Console.WriteLine(serialized); Console.WriteLine("Name value pairs elements missing"); Console.WriteLine(serialized2); } }
public void Deserialize_ArrayOfMyElement() { lock (testLock) { var e = new ArrayOfMyElement(); var myE = new MyElement {Name = "Name"}; myE.AttributeLists.Add(new NameValuePair {Name = "Name", Value = "Value"}); e.MyElement.Add(myE); Exception ex; var serialized = e.Serialize(); e.SaveToFile(Path.Combine(OutputFolder, "ReproSampleFile.xml"), out ex); if (ex != null) throw ex; //try to deserialize //generate doc conformant to schema ArrayOfMyElement toDeserialize; if (!ArrayOfMyElement.LoadFromFile("ReproSampleFile.xml", out toDeserialize, out ex)) { Console.WriteLine("Unable to deserialize, will exit"); return; } var serialized2 = toDeserialize.Serialize(); Console.WriteLine("Still missing the <NameValuePairElement>"); Console.WriteLine(serialized); Console.WriteLine("Name value pairs elements missing"); Console.WriteLine(serialized2); } }
/// <summary> /// Deserializes workflow markup from file into an MyElement object /// </summary> // <param name="xml">string workflow markup to deserialize</param> // <param name="obj">Output MyElement object</param> // <param name="exception">output Exception value if deserialize failed</param> // <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool LoadFromFile(string fileName, out MyElement obj, out System.Exception exception) { exception = null; obj = null; try { System.IO.FileStream file = new System.IO.FileStream(fileName, FileMode.Open, FileAccess.Read); System.IO.StreamReader sr = new System.IO.StreamReader(file); string xmlString = sr.ReadToEnd(); sr.Close(); file.Close(); return Deserialize(xmlString, out obj, out exception); } catch (System.Exception ex) { exception = ex; return false; } }
/// <summary> /// Deserializes workflow markup into an MyElement object /// </summary> // <param name="xml">string workflow markup to deserialize</param> // <param name="obj">Output MyElement object</param> // <param name="exception">output Exception value if deserialize failed</param> // <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool Deserialize(string xml, out MyElement obj, out System.Exception exception) { exception = null; obj = null; try { System.IO.StringReader stringReader = new System.IO.StringReader(xml); System.Xml.XmlTextReader xmlTextReader = new System.Xml.XmlTextReader(stringReader); System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(MyElement)); obj = ((MyElement)(xmlSerializer.Deserialize(xmlTextReader))); return true; } catch (System.Exception ex) { exception = ex; return false; } }