/// ------------------------------------------------------------------------------------ /// <summary> /// Deserializes XML from the specified file to an object of the specified type. /// </summary> /// <typeparam name="T">The object type</typeparam> /// <param name="filename">The filename from which to load</param> /// <param name="fKeepWhitespaceInElements">if set to <c>true</c>, the reader /// will preserve and return elements that contain only whitespace, otherwise /// these elements will be ignored during a deserialization.</param> /// <param name="e">The exception generated during the deserialization.</param> /// ------------------------------------------------------------------------------------ public static T DeserializeFromFile <T>(string filename, bool fKeepWhitespaceInElements, out Exception e) where T : class { T data = null; e = null; try { if (!File.Exists(filename)) { return(null); } using (XLiffXmlReader reader = new XLiffXmlReader( filename, fKeepWhitespaceInElements)) { data = DeserializeInternal <T>(reader); } } catch (Exception outEx) { e = outEx; } return(data); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Deserializes XML from the specified string to an object of the specified type. /// </summary> /// ------------------------------------------------------------------------------------ public static T DeserializeFromString <T>(string input, bool fKeepWhitespaceInElements, out Exception e) where T : class { T data = null; e = null; try { if (string.IsNullOrEmpty(input)) { return(null); } // Whitespace is not allowed before the XML declaration, // so get rid of any that exists. input = input.TrimStart(); using (XLiffXmlReader reader = new XLiffXmlReader( new StringReader(input), fKeepWhitespaceInElements)) { data = DeserializeInternal <T>(reader); } } catch (Exception outEx) { e = outEx; } return(data); }