ice7

Generic XML to C# Deserializer

Jun 29th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. public TResult ConvertFromXML<TResult>(string xml) where TResult : class, new()
  2.         {
  3.             TResult result;
  4.             var scrubXML = RemoveSoapBody(xml);         //Removes XML Soap Env from message
  5.  
  6.             using (MemoryStream ms = new MemoryStream(new ASCIIEncoding().GetBytes(scrubXML)))
  7.             {
  8.                 XmlSerializer cereal = new XmlSerializer(typeof(TResult));
  9.                 result = (TResult)cereal.Deserialize(ms);
  10.             }
  11.             return result;
Add Comment
Please, Sign In to add comment