using System.Runtime.Serialization;
public class SerializableHttpMethod
public string Method { get; set; }
public SerializableHttpMethod(HttpMethod method)
public HttpMethod ToHttpMethod()
return new HttpMethod(Method);
public SerializableHttpMethod HttpMethod { get; set; }
HttpMethod = new SerializableHttpMethod(HttpMethod.Get);
static void Main(string[] args)
var myObject = new MyClass();
string serializedObject = Serialize(myObject);
Console.WriteLine("Serialized object: " + serializedObject);
MyClass deserializedObject = Deserialize<MyClass>(serializedObject);
Console.WriteLine("Deserialized HttpMethod: " + deserializedObject.HttpMethod.ToHttpMethod());
static string Serialize<T>(T obj)
using (MemoryStream memoryStream = new MemoryStream())
DataContractSerializer serializer = new DataContractSerializer(typeof(T));
serializer.WriteObject(memoryStream, obj);
return Encoding.UTF8.GetString(memoryStream.ToArray());
static T Deserialize<T>(string xml)
using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
DataContractSerializer serializer = new DataContractSerializer(typeof(T));
return (T)serializer.ReadObject(memoryStream);