示例#1
0
 static void Main(string[] args)
 {
     UserMenuInfo info = new UserMenuInfo();
     info.MVC_ACT = "Kim";
     info.ORDERNUM = 100;
     SerializationWriter(info);
     BinaryFormaterObj(info);
     BinaryFormaterCommon();
     Console.ReadLine();
 }
示例#2
0
        private static void BinaryFormaterObj(UserMenuInfo info)
        {
            Console.WriteLine("BinaryFormatter-obj");
            string value = "";
            using (MemoryStream stream = new MemoryStream())
            {
                var binaryWriter = new BinaryFormatter();
                binaryWriter.Serialize(stream, info);
                value = Convert.ToBase64String(stream.ToArray());
                Console.WriteLine(value);
            }

            using (MemoryStream stream = new MemoryStream(Convert.FromBase64String(value)))
            {
                var binaryWriter = new BinaryFormatter();
                UserMenuInfo info2 = (UserMenuInfo)binaryWriter.Deserialize(stream);
                Console.WriteLine(info2.MVC_ACT);
            }
        }
示例#3
0
 private static void SerializationWriter(UserMenuInfo info)
 {
     Console.WriteLine("SerializationWriter");
     SerializationWriter writer = new SerializationWriter(new FileStream(AppDomain.CurrentDomain.BaseDirectory + "info.txt", FileMode.Create));
     writer.WriteObject(info);
 }