Extension method to Serialize/DeSerialize MSCRM Entity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ExtensionMethods | |
{ | |
//Serialize Entity | |
public static string serialize(this DynamicEntity dynamicEntity) | |
{ | |
StringWriter stringwriter = new StringWriter(); | |
XmlSerializer serilizer = new XmlSerializer(dynamicEntity.GetType()); | |
serilizer.Serialize(stringwriter, dynamicEntity); | |
return stringwriter.ToString(); | |
} | |
//Deserialize Entity | |
public static DynamicEntity deserialize(this string serializeEntity) | |
{ | |
var stringReader = new StringReader(serializeEntity); | |
var serializer = new XmlSerializer(typeof(DynamicEntity)); | |
return serializer.Deserialize(stringReader) as DynamicEntity; | |
} | |
} |