/// <summary> /// Converts the Data XML to the native type. This was necessary because WCF wanted the exact type, but it's only know at the source and destination. /// </summary> /// <typeparam name="T">Type to convert to</typeparam> /// <returns>Concrete type</returns> /// <exception cref="SerializationFailedException"></exception> public virtual T DataToType <T>() { if (Seralization == SeralizeAs.Xml) { try { return(Seralizer.StringToObject <T>(Data)); } catch (System.InvalidOperationException ex) { throw new SerializationFailedException($"Verify the type '{typeof(T)}' is the same type being passed in as the argument, otherwise check the inner exception", ex); } } else if (Seralization == SeralizeAs.Json) { try { return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(Data)); } catch (Newtonsoft.Json.JsonReaderException ex) { throw new SerializationFailedException($"Verify the type '{typeof(T)}' is the same type being passed in as the argument, otherwise check the inner exception", ex); } } else { throw new InvalidOperationException("Unknown encoding type selected"); } }