|
- using StuMgmLib.MyNameSpace;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
-
- namespace StuMgmClient
- {
- class Utility
- {
- //序列化
- internal static bool BinSerialize<T>(T data, out byte[] buff)
- {
- try
- {
- MemoryStream ms = new MemoryStream();
- BinaryFormatter iFormatter = new BinaryFormatter();
- iFormatter.Serialize(ms, data);
- buff = ms.GetBuffer();
- return true;
- }
- catch (Exception e)
- {
- Debug.Print(e.Message);
- buff = null;
- return false;
- }
- }
- //反序列化
- internal static bool BinDeserialize(byte[] data, out ServerResponse o)
- {
- try
- {
- MemoryStream ms = new MemoryStream(data);
- BinaryFormatter iFormatter = new BinaryFormatter();
- o = (ServerResponse)iFormatter.Deserialize(ms);
- return true;
- }
- catch (Exception e)
- {
- Debug.Print(e.Message);
- o = null;
- return false;
- }
- }
-
- //字典转字符串
- internal static string DicParsing(Dictionary<short, CourseStatusEnum> dic)
- {
- string stateText = "";
- foreach (var item in dic)
- {
- stateText = stateText + item.Key.ToString() + ":" + ((int)item.Value).ToString() + ";";
- }
- return stateText;
- }
- }
- }
|