public static T GetEntityByXml<T>(string xml, string rootNode=null) where T : new() { if (string.IsNullOrEmpty(xml)) return new T(); if (!string.IsNullOrEmpty(rootNode)) { xml = string.Format("<{0}>{1}</{0}>", rootNode, xml); } using (TextReader reader = new StringReader(xml)) { var serializer = new XmlSerializer(typeof(T)); return (T)serializer.Deserialize(reader); } }