static void Main(string[] args) { UserMenuInfo info = new UserMenuInfo(); info.MVC_ACT = "Kim"; info.ORDERNUM = 100; SerializationWriter(info); BinaryFormaterObj(info); BinaryFormaterCommon(); Console.ReadLine(); }
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); } }
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); }