SL没有Serializable标签
不能用,,,只能自己写一个
public static class SerializeHelper { public static byte[] Serialize(this object obj) { DataContractSerializer serializer = new DataContractSerializer(obj.GetType()); MemoryStream ms = new MemoryStream(); serializer.WriteObject(ms, obj); ms.Seek(0, 0); return ms.ToArray(); } public static T Deserialize<T>(this byte[] data) { DataContractSerializer serializer = new DataContractSerializer(typeof (T)); MemoryStream ms = new MemoryStream(data); ms.Seek(0, 0); return (T) (serializer.ReadObject(ms)); } public static string SerializeToString(this object obj) { DataContractSerializer serializer = new DataContractSerializer(obj.GetType()); MemoryStream ms = new MemoryStream(); serializer.WriteObject(ms, obj); return Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int) ms.Length); } public static T DeserializeFromString<T>(this string data) { byte[] buffer = Encoding.UTF8.GetBytes(data); DataContractSerializer serializer = new DataContractSerializer(typeof (T)); MemoryStream ms = new MemoryStream(buffer); ms.Seek(0, 0); return (T) (serializer.ReadObject(ms)); } }