コード例 #1
0
        int WriteStructList(object value, DataBuffer db, DataTypeInfo info)
        {
            var list = value as IList;

            if (list != null)
            {
                if (list.Count > 0)
                {
                    int    el  = info.ElementLength;
                    int    dl  = info.DataLength;
                    IntPtr ptr = UnsafeOperation.GetObjectAddr(list);
                    ptr = UnsafeOperation.GetListElement(ptr, 0);

                    FakeStructArray fsa = new FakeStructArray(db, el, list.Count);
                    unsafe
                    {
                        FakeStruct fs = new FakeStruct(db, el, fsa.ip);
                        for (int i = 0; i < list.Count; i++)
                        {
                            fs.SetPoint(fsa[i]);
                            WriteStruct(info, ptr, fs);
                            ptr += dl;
                        }
                    }
                    return(db.AddData(fsa, DataType.FakeStructArray));
                }
            }
            return(0);
        }
コード例 #2
0
        int WriteStructArray(object value, DataBuffer db, DataTypeInfo info)
        {
            var list = value as IList;

            if (list != null)
            {
                if (list.Count > 0)
                {
                    int             el  = info.ElementLength;
                    FakeStructArray fsa = new FakeStructArray(db, el, list.Count);
                    unsafe
                    {
                        FakeStruct fs = new FakeStruct(db, el, fsa.ip);
                        for (int i = 0; i < list.Count; i++)
                        {
                            fs.SetPoint(fsa[i]);
                            WriteStruct(info, list[i], fs);
                        }
                    }
                    return(db.AddData(fsa, DataType.FakeStructArray));
                }
            }
            return(0);
        }
コード例 #3
0
ファイル: DataReader.cs プロジェクト: huqiang0204/HGUI
 object ReadObjectList(DataFieldInfo info, DataBuffer buffer, Object obj)
 {
     if (obj != null)
     {
         Int16[] addr16 = obj as Int16[];
         if (addr16 != null)
         {
             var   con  = info.Construction();
             IList list = con as IList;
             for (int i = 0; i < addr16.Length; i++)
             {
                 var fs = buffer.GetData(addr16[i]) as FakeStruct;
                 if (fs != null)
                 {
                     list.Add(ReadObject(info.typeInfo, fs, addr16[i]));
                 }
                 else
                 {
                     list.Add(null);
                 }
             }
             return(con);
         }
         else
         {
             Int32[] addr32 = obj as Int32[];
             if (addr32 != null)
             {
                 bool  isStruct = info.typeInfo.isStruct;
                 var   con      = info.Construction();
                 IList list     = con as IList;
                 for (int i = 0; i < addr32.Length; i++)
                 {
                     int a     = addr32[i];
                     int index = a & 0xffff;
                     var fs    = buffer.GetData(index) as FakeStruct;
                     if (fs != null)
                     {
                         if (isStruct)//结构体无法使用继承
                         {
                             list.Add(ReadObject(info.typeInfo, fs, index));
                         }
                         else
                         {
                             var dt = oldTypes[a >> 16].NewType; //使用继承类型
                             if (dt == null)                     //没有找到继承类型则使用默认类型
                             {
                                 list.Add(null);
                             }
                             else
                             {
                                 list.Add(ReadObject(dt, fs, index));
                             }
                         }
                     }
                     else
                     {
                         list.Add(null);
                     }
                 }
                 return(con);
             }
             else
             {
                 FakeStructArray fsa = obj as FakeStructArray;
                 if (fsa != null)
                 {
                     FakeStruct fs;
                     unsafe
                     {
                         fs = new FakeStruct(buffer, fsa.StructSize, fsa.ip);
                     }
                     var   con  = info.Construction();
                     IList list = con as IList;
                     for (int i = 0; i < fsa.Length; i++)
                     {
                         unsafe { fs.SetPoint(fsa[i]); }
                         list.Add(ReadStruct(info.typeInfo, fs, 0));
                     }
                     return(con);
                 }
             }
         }
     }
     return(null);
 }
コード例 #4
0
ファイル: DataReader.cs プロジェクト: huqiang0204/HGUI
 object ReadObjectArray(DataFieldInfo info, DataBuffer buffer, Object obj)
 {
     if (obj != null)
     {
         Int16[] addr16 = obj as Int16[];
         if (addr16 != null)
         {
             var   con  = info.ArrayConstruction(addr16.Length);
             Array arry = con as Array;
             if (arry != null)
             {
                 for (int i = 0; i < addr16.Length; i++)
                 {
                     var fs = buffer.GetData(addr16[i]) as FakeStruct;
                     if (fs != null)
                     {
                         arry.SetValue(ReadObject(info.typeInfo, fs, addr16[i]), i);
                     }
                 }
             }
             return(con);
         }
         else
         {
             Int32[] addr32 = obj as Int32[];
             if (addr32 != null)
             {
                 bool  isStruct = info.typeInfo.isStruct;
                 var   con      = info.ArrayConstruction(addr32.Length);
                 Array arry     = con as Array;
                 if (arry == null)
                 {
                     for (int i = 0; i < addr32.Length; i++)
                     {
                         int a     = addr32[i];
                         int index = a & 0xffff;
                         var fs    = buffer.GetData(index) as FakeStruct;
                         if (fs != null)
                         {
                             if (isStruct)//结构体无法使用继承
                             {
                                 arry.SetValue(ReadObject(info.typeInfo, fs, index), i);
                             }
                             else
                             {
                                 var dt = oldTypes[a >> 16].NewType;//使用继承类型
                                 if (dt == null)
                                 {
                                     dt = info.typeInfo;
                                 }
                                 arry.SetValue(ReadObject(dt, fs, index), i);
                             }
                         }
                     }
                 }
                 return(con);
             }
             else
             {
                 FakeStructArray fsa = obj as FakeStructArray;
                 if (fsa != null)
                 {
                     FakeStruct fs;
                     unsafe
                     {
                         fs = new FakeStruct(buffer, fsa.StructSize, fsa.ip);
                     }
                     var   con  = info.ArrayConstruction(fsa.Length);
                     Array arry = con as Array;
                     if (arry != null)
                     {
                         for (int i = 0; i < fsa.Length; i++)
                         {
                             unsafe { fs.SetPoint(fsa[i]); }
                             arry.SetValue(ReadStruct(info.typeInfo, fs, 0), i);
                         }
                     }
                     return(con);
                 }
             }
         }
     }
     return(null);
 }
コード例 #5
0
 object ReadStructList(DataFieldInfo info, DataBuffer buffer, object obj)
 {
     if (obj != null)
     {
         Int16[] addr16 = obj as Int16[];
         if (addr16 != null)
         {
             var    con  = info.Construction();
             IList  list = con as IList;
             var    tmp  = info.typeInfo.Construction();
             IntPtr ptr  = UnsafeOperation.GetStructAddr(tmp);
             for (int i = 0; i < addr16.Length; i++)
             {
                 unsafe
                 {
                     byte *bp = (byte *)ptr;
                     for (int j = 0; j < info.typeInfo.DataLength; j++)
                     {
                         bp[j] = 0;
                     }
                 }
                 var fs = buffer.GetData(addr16[i]) as FakeStruct;
                 if (fs != null)
                 {
                     ReadStruct(info.typeInfo, fs, 0, ptr);
                 }
                 list.Add(tmp);
             }
             return(con);
         }
         else
         {
             Int32[] addr32 = obj as Int32[];
             if (addr32 != null)
             {
                 bool   isStruct = info.typeInfo.isStruct;
                 var    con      = info.Construction();
                 IList  list     = con as IList;
                 var    tmp      = info.typeInfo.Construction();
                 IntPtr ptr      = UnsafeOperation.GetStructAddr(tmp);
                 for (int i = 0; i < addr32.Length; i++)
                 {
                     unsafe
                     {
                         byte *bp = (byte *)ptr;
                         for (int j = 0; j < info.typeInfo.DataLength; j++)
                         {
                             bp[j] = 0;
                         }
                     }
                     int a     = addr32[i];
                     int index = a & 0xffff;
                     var fs    = buffer.GetData(index) as FakeStruct;
                     if (fs != null)
                     {
                         ReadStruct(info.typeInfo, fs, 0, ptr);
                     }
                     list.Add(tmp);
                 }
                 return(con);
             }
             else
             {
                 FakeStructArray fsa = obj as FakeStructArray;
                 if (fsa != null)
                 {
                     FakeStruct fs;
                     unsafe
                     {
                         fs = new FakeStruct(buffer, fsa.StructSize, fsa.ip);
                     }
                     var    con  = info.Construction();
                     IList  list = con as IList;
                     var    tmp  = info.typeInfo.Construction();
                     IntPtr ptr  = UnsafeOperation.GetStructAddr(tmp);
                     for (int i = 0; i < fsa.Length; i++)
                     {
                         unsafe
                         {
                             byte *bp = (byte *)ptr;
                             for (int j = 0; j < info.typeInfo.DataLength; j++)
                             {
                                 bp[j] = 0;
                             }
                         }
                         unsafe { fs.SetPoint(fsa[i]); }
                         ReadStruct(info.typeInfo, fs, 0, ptr);
                         list.Add(tmp);
                     }
                     return(con);
                 }
             }
         }
     }
     return(null);
 }
コード例 #6
0
 object ReadStructArray(DataFieldInfo info, DataBuffer buffer, object obj)
 {
     if (obj != null)
     {
         Int16[] addr16 = obj as Int16[];
         if (addr16 != null)
         {
             if (addr16.Length > 0)
             {
                 var   con  = info.ArrayConstruction(addr16.Length);
                 Array arry = con as Array;
                 if (arry != null)
                 {
                     IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arry, 0);
                     for (int i = 0; i < addr16.Length; i++)
                     {
                         var fs = buffer.GetData(addr16[i]) as FakeStruct;
                         if (fs != null)
                         {
                             ReadStruct(info.typeInfo, fs, 0, ptr);
                         }
                         ptr += info.DataLength;
                     }
                 }
                 return(con);
             }
         }
         else
         {
             Int32[] addr32 = obj as Int32[];
             if (addr32 != null)
             {
                 bool  isStruct = info.typeInfo.isStruct;
                 var   con      = info.ArrayConstruction(addr32.Length);
                 Array arry     = con as Array;
                 if (arry == null)
                 {
                     IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arry, 0);
                     for (int i = 0; i < addr32.Length; i++)
                     {
                         int a     = addr32[i];
                         int index = a & 0xffff;
                         var fs    = buffer.GetData(index) as FakeStruct;
                         if (fs != null)
                         {
                             ReadStruct(info.typeInfo, fs, 0, ptr);
                         }
                         ptr += info.DataLength;
                     }
                 }
                 return(con);
             }
             else
             {
                 FakeStructArray fsa = obj as FakeStructArray;
                 if (fsa != null)
                 {
                     FakeStruct fs;
                     unsafe
                     {
                         fs = new FakeStruct(buffer, fsa.StructSize, fsa.ip);
                     }
                     var   con  = info.ArrayConstruction(fsa.Length);
                     Array arry = con as Array;
                     if (arry != null)
                     {
                         IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arry, 0);
                         for (int i = 0; i < fsa.Length; i++)
                         {
                             unsafe { fs.SetPoint(fsa[i]); }
                             ReadStruct(info.typeInfo, fs, 0, ptr);
                             ptr += info.DataLength;
                         }
                     }
                     return(con);
                 }
             }
         }
     }
     return(null);
 }