Esempio n. 1
0
 //TODO:优化静态序列化方法设计
 public static string Serialize(object obj, Type target)
 {
     if (target == null || obj == null)
     {
         return("null");
     }
     using (var stream = new MemoryStream())
         using (var reader = new StreamReader(stream))
         {
             WorkflowBuilder.CreateSerializer(target).WriteObject(stream, obj);
             stream.Position = 0;
             return(reader.ReadToEnd());
         }
 }
Esempio n. 2
0
 public static object Deserialize(Type target, string input)
 {
     using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(input)))
         return(WorkflowBuilder.CreateSerializer(target).ReadObject(stream));
 }