public static List <OrganizeAttr> LoadOrganizeInfos(string file, bool reload = false) { if (!reload && m_OrganizeAttrList.Count != 0) { return(m_OrganizeAttrList); } List <OrganizeAttr> OrganizeAttrList = new List <OrganizeAttr>(); OrganizeAttrList.Clear(); string dbfile = file; if (!File.Exists(dbfile)) { OrganizeAttrList.Clear(); return(OrganizeAttrList); } if (File.Exists(@".\\Temp\\organize.dat")) { File.SetAttributes(@".\\Temp\\organize.dat", FileAttributes.Normal); File.Copy(dbfile, @".\\Temp\\organize.dat", true); } else { File.Copy(dbfile, @".\\Temp\\organize.dat", false); } FileStream fs = new FileStream(".\\Temp\\organize.dat", FileMode.Open, FileAccess.ReadWrite); OrganizeAttrHead head = new OrganizeAttrHead(); int ret = 0; byte[] bytData = new byte[Marshal.SizeOf(head)]; ret = fs.Read(bytData, 0, Marshal.SizeOf(head)); while (ret > 0) { OrganizeAttr aa = new OrganizeAttr(); byte[] _bytData = new byte[Marshal.SizeOf(aa)]; ret = fs.Read(_bytData, 0, Marshal.SizeOf(aa)); if (ret <= 0) { break; } OrganizeAttr attr = CStructBytesFormat.BytesToStruct <OrganizeAttr>(_bytData); OrganizeAttrList.Add(attr); } fs.Close(); //更新本地list m_OrganizeAttrList.Clear(); m_OrganizeAttrList = OrganizeAttrList; return(m_OrganizeAttrList); }
public static Tran_Head GetDataHead(byte[] data) { Tran_Head head = new Tran_Head(); byte[] rcv_head = new byte[Marshal.SizeOf(head)]; Array.ConstrainedCopy(data, 0, rcv_head, 0, Marshal.SizeOf(head)); head = (Tran_Head)CStructBytesFormat.BytesToStruct <Tran_Head>(rcv_head); return(head); }
public static T GetDataObj <T>(byte[] data, Tran_Head head) { if (data == null) { return(default(T)); } if (data.Length <= 0) { return(default(T)); } int objLength = Marshal.SizeOf(typeof(T)); byte[] rcv_data = new byte[head.length]; T obj; Array.ConstrainedCopy(data, Marshal.SizeOf(head), rcv_data, 0, rcv_data.Length); obj = (T)CStructBytesFormat.BytesToStruct <T>(rcv_data); return(obj); }