/* * 由SharpDevelop创建。 * 用户: Administrator * 日期: 2017-08-17 * 时间: 14:36 * * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件 */ using System; using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace nativeCom { public interface huMnemonic{ void Clear(); } public static class baseFuntion{ /// /// 清空一个int数组 /// /// public static void ClearIntArray(ref int[] array){ int len = array.Length; for(int i=0;i /// 把array1中的值完全拷贝到array2中 /// /// array1 /// array2 /// 从那个开始拷贝 public static void CopyArray(ref int[] array1,ref int[] array2,int idx){ int length = array1.Length; Array.Copy(array1,0,array2,idx,length); } /// /// 序列化 /// /// /// public static void Serizeable(Object obj,string path){ // try{ FileStream stream = new FileStream(path,FileMode.OpenOrCreate); BinaryFormatter binary = new BinaryFormatter(); binary.Serialize(stream,obj); stream.Close(); stream.Dispose(); // }catch(Exception e){ // Form1.log("序列化失败:" + e.ToString()); // } } /// /// 反序列化 /// /// /// public static Object DeSerizeable(string path){ if(!File.Exists(path)) return null; // try{ FileStream stream = new FileStream(path,FileMode.Open); BinaryFormatter binary = new BinaryFormatter(); Object obj = binary.Deserialize(stream); stream.Close(); stream.Dispose(); return obj; // }catch(Exception e){ // Form1.log("反序列化失败:" + e.ToString()); // return null; // } } /// /// 序列化到内存流 /// /// /// /// public static MemoryStream Serizeable(Object obj){ MemoryStream ms = null; // try{ ms = new MemoryStream(); BinaryFormatter binary = new BinaryFormatter(); binary.Serialize(ms,obj); // }catch(Exception e){ // Form1.log("序列化到内存失败:" + e.ToString()); // } return ms; } /// /// 序列化内存流 /// /// /// public static Object DeSerizeable(MemoryStream ms){ ms.Position = 0; Object obj; // try{ BinaryFormatter binary = new BinaryFormatter(); obj = binary.Deserialize(ms); // }catch(Exception e){ // Form1.log("内存反序列化失败:" + e.ToString()); // return null; // } return obj; } /// /// 克隆 /// /// /// public static Object Clone(Object obj){ MemoryStream ms = Serizeable(obj); Object tmp = DeSerizeable(ms); ms.Close(); ms.Dispose(); return tmp; } /// /// 字符数装数字 /// /// 0-9 /// public static sbyte charToInt(this char ch){ return (sbyte)(ch-48); } } }