xml序列化与反序列化

                using System.Xml.Serialization;

                 //--将对象sm序列化成二进制流

         ScheduleMethod sm = new ScheduleMethod();

                MemoryStream s = new MemoryStream();
                XmlSerializer serializer = new XmlSerializer(sm.GetType());
                serializer.Serialize(s, sm);
                byte[] file = s.ToArray();
            
                 //从数据库获得二进制流并转换成sm对象       

                entity.ScheduleEntity sch = deviceMAN.GetModelSchedule(scheduleid);
                MemoryStream m = new MemoryStream(sch.RecurrenceMethod);
                ScheduleMethod sm=(ScheduleMethod)serialzer.Deserialize(m);

posted @ 2010-10-28 15:01  我的食草堂  阅读(151)  评论(0编辑  收藏  举报