public static bool TryLoad(string str, out cPanelResult <TResponse> res) { MemoryStream ms = new MemoryStream(); StreamWriter writer = new StreamWriter(ms); writer.Write(str); writer.Flush(); ms.Position = 0; return(TryLoad(ms, out res)); }
public static bool TrySave(out string str, cPanelResult <TResponse> res) { MemoryStream ms = new MemoryStream(); bool result = TrySave(ms, res); ms.Position = 0; StreamReader reader = new StreamReader(ms); str = reader.ReadToEnd(); return(result); }
public static bool TrySave(Stream s, cPanelResult <TResponse> res) { Type[] tArray = new Type[] { typeof(TResponse) }; XmlSerializer ser = new XmlSerializer(res.GetType(), tArray); try { ser.Serialize(s, res); } catch (Exception e) { Console.WriteLine("XML Serialization Failure: " + e.Message); } return(true); }
public static bool TryLoad(Stream s, out cPanelResult <TResponse> res) { res = new cPanelResult <TResponse>(); Type[] tArray = new Type[] { typeof(TResponse) }; try { XmlSerializer ser = new XmlSerializer(res.GetType(), tArray); ser.UnknownAttribute += new XmlAttributeEventHandler(XmlUnknownAttribute); ser.UnknownNode += new XmlNodeEventHandler(XmlUnknownNode); res = (cPanelResult <TResponse>)ser.Deserialize(s); } catch (Exception e) { Console.WriteLine("XML Serialization Failure: " + e.Message); return(false); } return(true); }