Beispiel #1
0
 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);
 }
Beispiel #2
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);
 }