예제 #1
0
 void WriteValue(FakeStruct fake, int offset, DataFieldInfo info, object instance)
 {
     if (info.DBType < 6)
     {
         fake[offset] = Convert.ToInt32(info.field.GetValue(instance));
     }
     else if (info.DBType == DataType2.Float)
     {
         fake.SetFloat(offset, Convert.ToSingle(info.field.GetValue(instance)));
     }
     else if (info.DBType < 8)
     {
         fake.SetInt64(offset, Convert.ToInt64(info.field.GetValue(instance)));
     }
     else if (info.DBType == DataType2.Double)
     {
         fake.SetDouble(offset, Convert.ToDouble(info.field.GetValue(instance)));
     }
     else if (info.DBType == DataType2.Decimal)
     {
         fake.SetDecimal(offset, Convert.ToDecimal(info.field.GetValue(instance)));
     }
     else if (info.DBType == DataType2.Boolean)
     {
         fake[offset] = Convert.ToInt32(info.field.GetValue(instance));
     }
     else if (info.DBType == 12)
     {
         WriteStruct(fake, offset, info, info.field.GetValue(instance));
     }
 }
예제 #2
0
        void WriteStruct(FakeStruct fake, int start, DataFieldInfo info, IntPtr ptr)
        {
            var dts = info.typeInfo.dataFeilds;

            for (int i = 0; i < dts.Count; i++)
            {
                WriteField(fake, start, dts[i], ptr);
            }
        }
예제 #3
0
        void WriteStruct(FakeStruct fake, int start, DataFieldInfo info, object instance)
        {
            var dts = info.typeInfo.dataFeilds;

            for (int i = 0; i < dts.Count; i++)
            {
                WriteField(fake, start, dts[i], instance);
            }
        }
예제 #4
0
        object ReadArray2(DataFieldInfo info, FakeStruct fake, int offset)
        {
            Int16[] tmp = fake.GetData <Int16[]>(offset);
            if (tmp == null)
            {
                return(null);
            }
            var   buf  = fake.buffer;
            Array arry = info.ArrayConstruction2(tmp.Length) as Array;
            int   a    = info.DBType;

            a &= 0x1f;
            switch (a)
            {
            case DataType2.Class:
            case DataType2.Struct:
                for (int i = 0; i < tmp.Length; i++)
                {
                    var v = buf.GetData(tmp[i]);
                    if (v != null)
                    {
                        var obj = ReadObjectArray(info, buf, v);
                        if (obj != null)
                        {
                            arry.SetValue(obj, i);
                        }
                    }
                }
                break;

            case DataType2.String:
                for (int i = 0; i < tmp.Length; i++)
                {
                    var v = buf.GetData(tmp[i]) as FakeStringArray;
                    if (v != null)
                    {
                        arry.SetValue(v.Data, i);
                    }
                }
                break;

            default:
                for (int i = 0; i < tmp.Length; i++)
                {
                    var v = buf.GetData(tmp[i]);
                    if (v != null)
                    {
                        arry.SetValue(v, i);
                    }
                }
                break;
            }
            return(arry);
        }
예제 #5
0
        void WriteArray2(FakeStruct fake, int offset, DataFieldInfo info, IntPtr ptr)
        {
            var    buffer = fake.buffer;
            object value;

            value = UnsafeOperation.GetObject(ptr + info.MemOffset);
            if (value == null)
            {
                return;
            }
            int a = info.DBType & 31;

            switch (a)
            {
            case DataType2.Byte:
                fake[offset] = WriteArray2 <byte>(value, buffer, DataType.ByteArray);
                break;

            case DataType2.Int16:
                fake[offset] = WriteArray2 <Int16>(value, buffer, DataType.ByteArray);
                break;

            case DataType2.Int32:
                fake[offset] = WriteArray2 <Int32>(value, buffer, DataType.ByteArray);
                break;

            case DataType2.Float:
                fake[offset] = WriteArray2 <float>(value, buffer, DataType.ByteArray);
                break;

            case DataType2.String:
                fake[offset] = WriteStringArray2(value, buffer, DataType.ByteArray);
                break;

            case DataType2.Int64:
                fake[offset] = WriteArray2 <Int64>(value, buffer, DataType.ByteArray);
                break;

            case DataType2.Double:
                fake[offset] = WriteArray2 <Double>(value, buffer, DataType.ByteArray);
                break;

            case DataType2.Class:
                fake[offset] = WriteClassArray2(value, fake.buffer, info);
                break;

            case DataType2.Struct:
                fake[offset] = WriteStructArray2(value, fake.buffer, info);
                break;
            }
        }
예제 #6
0
        void WriteArray2(FakeStruct fake, int offset, DataFieldInfo info, object instance)
        {
            var buffer = fake.buffer;
            var value  = info.field.GetValue(instance);

            if (value == null)
            {
                return;
            }
            int a = info.DBType & 31;

            switch (a)
            {
            case DataType2.Byte:
                fake[offset] = WriteArray2 <byte>(value, buffer, DataType.ByteArray);
                break;

            case DataType2.Int16:
                fake[offset] = WriteArray2 <Int16>(value, buffer, DataType.ByteArray);
                break;

            case DataType2.Int32:
                fake[offset] = WriteArray2 <Int32>(value, buffer, DataType.ByteArray);
                break;

            case DataType2.Float:
                fake[offset] = WriteArray2 <float>(value, buffer, DataType.ByteArray);
                break;

            case DataType2.String:
                fake[offset] = WriteStringArray2(value, buffer, DataType.ByteArray);
                break;

            case DataType2.Int64:
                fake[offset] = WriteArray2 <Int64>(value, buffer, DataType.ByteArray);
                break;

            case DataType2.Double:
                fake[offset] = WriteArray2 <Double>(value, buffer, DataType.ByteArray);
                break;

            case DataType2.Class:
                fake[offset] = WriteClassArray2(info.field.GetValue(instance), fake.buffer, info);
                break;

            case DataType2.Struct:
                fake[offset] = WriteStructArray2(info.field.GetValue(instance), fake.buffer, info);
                break;
            }
        }
예제 #7
0
        object ReadArray(DataFieldInfo info, FakeStruct fake, int offset)
        {
            int a = info.DBType;

            a &= 0x1f;
            switch (a)
            {
            case DataType2.Class:
            case DataType2.Struct:
                return(ReadObjectArray(info, fake.buffer, fake.GetData(offset)));

            case DataType2.String:
                return(fake.GetData <FakeStringArray>(offset).Data);

            default: return(fake.GetData(offset));
            }
        }
예제 #8
0
        object ReadList(DataFieldInfo info, FakeStruct fake, int offset)
        {
            int a = info.DBType;

            a &= 0x1f;
            switch (a)
            {
            case DataType2.Byte:
                return(ReadArray <byte>(fake.GetData(offset)));

            case DataType2.Int16:
                return(ReadArray <Int16>(fake.GetData(offset)));

            case DataType2.Int32:
                return(ReadArray <Int32>(fake.GetData(offset)));

            case DataType2.Int64:
                return(ReadArray <Int64>(fake.GetData(offset)));

            case DataType2.Float:
                return(ReadArray <float>(fake.GetData(offset)));

            case DataType2.Double:
                return(ReadArray <Double>(fake.GetData(offset)));

            case DataType2.Class:
                return(ReadObjectList(info, fake.buffer, fake.GetData(offset)));

            case DataType2.Struct:
                return(ReadStructList(info, fake.buffer, fake.GetData(offset)));

            case DataType2.String:
            {
                var fsa = fake.GetData <FakeStringArray>(offset);
                if (fsa != null)
                {
                    List <string> list = new List <string>();
                    list.AddRange(fsa.Data);
                    return(list);
                }
            }
                return(null);

            default: return(fake.GetData(offset));
            }
        }
예제 #9
0
 void WriteValue(FakeStruct fake, int offset, DataFieldInfo info, IntPtr ptr)
 {
     if (info.DBType < 6)
     {
         if (info.DataLength == 1)
         {
             unsafe { fake[offset] = *(byte *)(ptr + info.MemOffset); }
         }
         else if (info.DataLength == 2)
         {
             unsafe { fake[offset] = *(Int16 *)(ptr + info.MemOffset); }
         }
         else
         {
             unsafe { fake[offset] = *(Int32 *)(ptr + info.MemOffset); }
         }
     }
     else if (info.DBType == DataType2.Float)
     {
         unsafe { fake.SetFloat(offset, *(float *)(ptr + info.MemOffset)); }
     }
     else if (info.DBType < 8)
     {
         unsafe { fake.SetInt64(offset, *(Int64 *)(ptr + info.MemOffset)); }
     }
     else if (info.DBType == DataType2.Double)
     {
         unsafe { fake.SetDouble(offset, *(Double *)(ptr + info.MemOffset)); }
     }
     else if (info.DBType == DataType2.Decimal)
     {
         unsafe { fake.SetDecimal(offset, *(Decimal *)(ptr + info.MemOffset)); }
     }
     else if (info.DBType == DataType2.Boolean)
     {
         unsafe { fake[offset] = *(byte *)(ptr + info.MemOffset); }
     }
     else if (info.DBType == 12)
     {
         WriteStruct(fake, offset, info, ptr + info.MemOffset);
     }
 }
예제 #10
0
        void WriteField(FakeStruct fake, int start, DataFieldInfo info, object instance)
        {
            int offset = start + info.DataOffset;

            if (info.DBType < 32)
            {
                if (info.DBType < 16)//数值
                {
                    WriteValue(fake, offset, info, instance);
                }
                else//引用类型
                {
                    if (info.DBType == DataType2.String)
                    {
                        var obj = info.field.GetValue(instance);
                        if (obj != null)
                        {
                            fake[offset] = fake.buffer.AddData(obj, DataType.String);
                        }
                    }
                    else
                    {
                        var obj = info.field.GetValue(instance);
                        if (obj != null)
                        {
                            fake[offset] = WriteObject(info.TypeFullName, obj, fake.buffer);
                        }
                    }
                }
            }
            else if (info.DBType < 64)//数组
            {
                WriteArray(fake, offset, info, instance);
            }
            else//二维数组
            {
                WriteArray2(fake, offset, info, instance);
            }
        }
예제 #11
0
        void WriteField(FakeStruct fake, int start, DataFieldInfo info, IntPtr ptr)
        {
            int offset = start + info.DataOffset;

            if (info.DBType < 32)
            {
                if (info.DBType < 16)//数值
                {
                    WriteValue(fake, offset, info, ptr);
                }
                else//引用类型
                {
                    if (info.DBType == DataType2.String)
                    {
                        var obj = UnsafeOperation.GetObject(ptr + info.MemOffset);
                        if (obj != null)
                        {
                            fake[offset] = fake.buffer.AddData(obj, DataType.String);
                        }
                    }
                    else
                    {
                        var obj = UnsafeOperation.GetObject(ptr + info.MemOffset);
                        if (obj != null)
                        {
                            fake[offset] = WriteObject(info.TypeFullName, obj, fake.buffer);
                        }
                    }
                }
            }
            else if (info.DBType < 64)//数组
            {
                WriteArray(fake, offset, info, ptr);
            }
            else//二维数组
            {
                WriteArray2(fake, offset, info, ptr);
            }
        }
예제 #12
0
        int WriteClassArray2(object value, DataBuffer db, DataFieldInfo info)
        {
            var list = value as IList;

            if (list != null)
            {
                int c = list.Count;
                if (c > 0)
                {
                    Int16[] addr = new short[c];
                    for (int i = 0; i < c; i++)
                    {
                        var obj = list[i];
                        if (obj != null)
                        {
                            addr[i] = (Int16)WriteClassArray(obj, db, info.typeInfo);
                        }
                    }
                    return(db.AddData(addr, DataType.Int16Array));
                }
            }
            return(0);
        }
예제 #13
0
        public void Analysis(DataInfo analysis, Type typ)
        {
            type     = typ;
            name     = type.Name;
            fullName = type.FullName;
            isStruct = typ.IsValueType;
            var fs   = typ.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            int len  = 0;
            int dlen = 0;

            dataFeilds = new List <DataFieldInfo>();
            for (int i = 0; i < fs.Length; i++)
            {
                if (fs[i].IsPublic | fs[i].IsDefined(typeof(SerializeField)))
                {
                    if (!fs[i].IsStatic)
                    {
                        if (!fs[i].IsNotSerialized)
                        {
                            if (fs[i].FieldType.Name != DataType2.Action)
                            {
                                DataFieldInfo df = new DataFieldInfo();
                                df.Analysis(analysis, fs[i]);
                                if (analysis.Unsafe)
                                {
                                    df.MemOffset = UnsafeOperation.GetFeildOffset(df.field.FieldHandle.Value, isStruct);
                                }
                                df.DataOffset = (Int16)len;
                                len          += df.ElementLength;
                                dlen         += df.DataLength;
                                dataFeilds.Add(df);
                            }
                        }
                    }
                }
            }
            DataLength    = dlen;
            ElementLength = (Int16)len;
            if (analysis.CreateConstruction)
            {
#if ENABLE_MONO
                try
                {
                    if (isStruct)
                    {
                        Construction = DataInfo.GetCreateStructFunc(typ);
                    }
                    else
                    {
                        Construction = DataInfo.GetCreateFunc(typ);
                    }
                }catch
                {
                    Debug.LogError("Construction Error ! " + typ.Name);
                    throw (new Exception());
                }
#else
                Construction = () => { return(Activator.CreateInstance(type)); };
#endif
            }
        }
예제 #14
0
        object ReadList2(DataFieldInfo info, FakeStruct fake, int offset)
        {
            Int16[] tmp = fake.GetData <Int16[]>(offset);
            if (tmp == null)
            {
                return(null);
            }
            var   buf  = fake.buffer;
            IList arry = info.Construction2() as IList;
            int   a    = info.DBType;

            a &= 0x1f;
            switch (a)
            {
            case DataType2.Class:
            case DataType2.Struct:
                for (int i = 0; i < tmp.Length; i++)
                {
                    var v = buf.GetData(tmp[i]);
                    if (v != null)
                    {
                        object obj;
                        if (info.ChildTypeName == DataType2.List)
                        {
                            obj = ReadObjectList(info, buf, v);
                        }
                        else
                        {
                            obj = ReadObjectArray(info, buf, v);
                        }
                        arry.Add(obj);
                    }
                    else
                    {
                        arry.Add(null);
                    }
                }
                break;

            case DataType2.String:
                if (info.ChildTypeName == DataType2.List)
                {
                    for (int i = 0; i < tmp.Length; i++)
                    {
                        var v = buf.GetData(tmp[i]) as FakeStringArray;
                        if (v != null)
                        {
                            List <string> t = new List <string>();
                            t.AddRange(v.Data);
                            arry.Add(t);
                        }
                        else
                        {
                            arry.Add(null);
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < tmp.Length; i++)
                    {
                        var v = buf.GetData(tmp[i]) as FakeStringArray;
                        if (v != null)
                        {
                            arry.Add(v.Data);
                        }
                        else
                        {
                            arry.Add(null);
                        }
                    }
                }
                break;

            default:
                if (info.ChildTypeName == DataType2.List)
                {
                    switch (a)
                    {
                    case DataType2.Byte:
                        for (int i = 0; i < tmp.Length; i++)
                        {
                            arry.Add(ReadArray <byte>(buf.GetData(tmp[i])));
                        }
                        break;

                    case DataType2.Int16:
                        for (int i = 0; i < tmp.Length; i++)
                        {
                            arry.Add(ReadArray <Int16>(buf.GetData(tmp[i])));
                        }
                        break;

                    case DataType2.Int32:
                        for (int i = 0; i < tmp.Length; i++)
                        {
                            arry.Add(ReadArray <Int32>(buf.GetData(tmp[i])));
                        }
                        break;

                    case DataType2.Int64:
                        for (int i = 0; i < tmp.Length; i++)
                        {
                            arry.Add(ReadArray <Int64>(buf.GetData(tmp[i])));
                        }
                        break;

                    case DataType2.Float:
                        for (int i = 0; i < tmp.Length; i++)
                        {
                            arry.Add(ReadArray <float>(buf.GetData(tmp[i])));
                        }
                        break;

                    case DataType2.Double:
                        for (int i = 0; i < tmp.Length; i++)
                        {
                            arry.Add(ReadArray <double>(buf.GetData(tmp[i])));
                        }
                        break;
                    }
                }
                else
                {
                    for (int i = 0; i < tmp.Length; i++)
                    {
                        arry.Add(buf.GetData(tmp[i]));
                    }
                }
                break;
            }
            return(arry);
        }
예제 #15
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);
 }
예제 #16
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);
 }
예제 #17
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);
 }
예제 #18
0
 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);
 }
예제 #19
0
        void WriteArray(FakeStruct fake, int offset, DataFieldInfo info, object instance)
        {
            var buffer = fake.buffer;
            var value  = info.field.GetValue(instance);

            if (value == null)
            {
                return;
            }
            int a = info.DBType & 31;

            if (info.TypeName == "List`1")
            {
                switch (a)
                {
                case DataType2.Byte:
                    fake[offset] = buffer.AddData(ToArray <byte>(value), DataType.ByteArray);
                    break;

                case DataType2.Int16:
                    fake[offset] = buffer.AddData(ToArray <Int16>(value), DataType.Int16Array);
                    break;

                case DataType2.Int32:
                    fake[offset] = buffer.AddData(ToArray <Int32>(value), DataType.Int32Array);
                    break;

                case DataType2.Float:
                    fake[offset] = buffer.AddData(ToArray <float>(value), DataType.FloatArray);
                    break;

                case DataType2.String:
                {
                    string[] str = ToArray <string>(value);
                    if (str != null)
                    {
                        fake[offset] = buffer.AddData(new FakeStringArray(str), DataType.FakeStringArray);
                    }
                }
                break;

                case DataType2.Int64:
                    fake[offset] = buffer.AddData(ToArray <Int64>(value), DataType.Int64Array);
                    break;

                case DataType2.Double:
                    fake[offset] = buffer.AddData(ToArray <Double>(value), DataType.DoubleArray);
                    break;

                case DataType2.Class:
                    fake[offset] = WriteClassArray(value, fake.buffer, info.typeInfo);
                    break;

                case DataType2.Struct:
                    fake[offset] = WriteStructArray(value, fake.buffer, info.typeInfo);
                    break;
                }
            }
            else
            {
                switch (a)
                {
                case DataType2.Byte:
                    fake[offset] = buffer.AddData(value, DataType.ByteArray);
                    break;

                case DataType2.Int16:
                    fake[offset] = buffer.AddData(value, DataType.Int16Array);
                    break;

                case DataType2.Int32:
                    fake[offset] = buffer.AddData(value, DataType.Int32Array);
                    break;

                case DataType2.Float:
                    fake[offset] = buffer.AddData(value, DataType.FloatArray);
                    break;

                case DataType2.String:
                    fake[offset] = buffer.AddData(new FakeStringArray(value as string[]), DataType.FakeStringArray);
                    break;

                case DataType2.Int64:
                    fake[offset] = buffer.AddData(value, DataType.Int64Array);
                    break;

                case DataType2.Double:
                    fake[offset] = buffer.AddData(value, DataType.DoubleArray);
                    break;

                case DataType2.Class:
                    fake[offset] = WriteClassArray(value, fake.buffer, info.typeInfo);
                    break;

                case DataType2.Struct:
                    fake[offset] = WriteStructArray(value, fake.buffer, info.typeInfo);
                    break;
                }
            }
        }
예제 #20
0
        void CompatibleReadValue(DataFieldInfo info, FakeStruct fake, int offset, IntPtr ptr)
        {
            switch (info.DBType)
            {
            case DataType2.Byte:
                unsafe { *(byte *)(ptr + info.MemOffset) = (byte)fake[offset]; }
                break;

            case DataType2.SByte:
                unsafe { *(sbyte *)(ptr + info.MemOffset) = (sbyte)fake[offset]; }
                break;

            case DataType2.Int16:
                unsafe { *(Int16 *)(ptr + info.MemOffset) = (Int16)fake[offset]; }
                break;

            case DataType2.UInt16:
                unsafe { *(UInt16 *)(ptr + info.MemOffset) = (UInt16)fake[offset]; }
                break;

            case DataType2.Int32:
                unsafe { *(Int32 *)(ptr + info.MemOffset) = (Int32)fake[offset]; }
                break;

            case DataType2.UInt32:
                unsafe { *(UInt32 *)(ptr + info.MemOffset) = (UInt32)fake[offset]; }
                break;

            case DataType2.Float:
                unsafe { *(float *)(ptr + info.MemOffset) = fake.GetFloat(offset); }
                break;

            case DataType2.Int64:
            case DataType2.UInt64:
                if (info.OldFieldInfo.DataLength == 4)
                {
                    unsafe { *(Int32 *)(ptr + info.MemOffset) = (Int32)fake[offset]; }
                }
                else
                {
                    unsafe { *(Int64 *)(ptr + info.MemOffset) = fake.GetInt64(offset); }
                }
                break;

            case DataType2.Double:
                if (info.OldFieldInfo.DataLength == 4)
                {
                    unsafe { *(float *)(ptr + info.MemOffset) = fake.GetFloat(offset); }
                }
                else
                {
                    unsafe { *(double *)(ptr + info.MemOffset) = fake.GetDouble(offset); }
                }
                break;

            case DataType2.Decimal:
                if (info.OldFieldInfo.DataLength == 4)
                {
                    unsafe { *(float *)(ptr + info.MemOffset) = fake.GetFloat(offset); }
                }
                else if (info.OldFieldInfo.DataLength == 8)
                {
                    unsafe { *(double *)(ptr + info.MemOffset) = fake.GetDouble(offset); }
                }
                else
                {
                    unsafe { *(decimal *)(ptr + info.MemOffset) = fake.GetDecimal(offset); }
                }
                break;
            }
        }
예제 #21
0
        void WriteArray(FakeStruct fake, int offset, DataFieldInfo info, IntPtr ptr)
        {
            var    buffer = fake.buffer;
            object value;

            value = UnsafeOperation.GetObject(ptr + info.MemOffset);
            if (value == null)
            {
                return;
            }
            int a = info.DBType & 31;

            if (info.TypeName == DataType2.List)
            {
                switch (a)
                {
                case DataType2.Byte:
                    fake[offset] = buffer.AddData(ToArray <byte>(value), DataType.ByteArray);
                    break;

                case DataType2.Int16:
                    fake[offset] = buffer.AddData(ToArray <Int16>(value), DataType.Int16Array);
                    break;

                case DataType2.Int32:
                    fake[offset] = buffer.AddData(ToArray <Int32>(value), DataType.Int32Array);
                    break;

                case DataType2.Float:
                    fake[offset] = buffer.AddData(ToArray <float>(value), DataType.FloatArray);
                    break;

                case DataType2.String:
                {
                    string[] str = ToArray <string>(value);
                    if (str != null)
                    {
                        fake[offset] = buffer.AddData(new FakeStringArray(str), DataType.FakeStringArray);
                    }
                }
                break;

                case DataType2.Int64:
                    fake[offset] = buffer.AddData(ToArray <Int64>(value), DataType.Int64Array);
                    break;

                case DataType2.Double:
                    fake[offset] = buffer.AddData(ToArray <Double>(value), DataType.DoubleArray);
                    break;

                case DataType2.Class:
                    fake[offset] = WriteClassArray(value, fake.buffer, info.typeInfo);
                    break;

                case DataType2.Struct:
                    fake[offset] = WriteStructList(value, fake.buffer, info.typeInfo);
                    break;
                }
            }
            else
            {
                switch (a)
                {
                case DataType2.Byte:
                    fake[offset] = buffer.AddData(value, DataType.ByteArray);
                    break;

                case DataType2.Int16:
                    fake[offset] = buffer.AddData(value, DataType.Int16Array);
                    break;

                case DataType2.Int32:
                    fake[offset] = buffer.AddData(value, DataType.Int32Array);
                    break;

                case DataType2.Float:
                    fake[offset] = buffer.AddData(value, DataType.FloatArray);
                    break;

                case DataType2.String:
                    fake[offset] = buffer.AddData(new FakeStringArray(value as string[]), DataType.FakeStringArray);
                    break;

                case DataType2.Int64:
                    fake[offset] = buffer.AddData(value, DataType.Int64Array);
                    break;

                case DataType2.Double:
                    fake[offset] = buffer.AddData(value, DataType.DoubleArray);
                    break;

                case DataType2.Class:
                    fake[offset] = WriteClassArray(value, fake.buffer, info.typeInfo);
                    break;

                case DataType2.Struct:
                    fake[offset] = WriteStructArray(value, fake.buffer, info.typeInfo);
                    break;
                }
            }
        }
예제 #22
0
        void ReadField(FakeStruct fake, int start, DataFieldInfo info, object instance)
        {
            int offset = start + info.OldFieldInfo.DataOffset;

            if (info.DBType < 11)
            {
                CompatibleReadValue(info, fake, offset, instance);
            }
            else if (info.DBType < 32)
            {
                switch (info.DBType)
                {
                case DataType2.String:
                    string str = fake.GetData <string>(offset);
                    if (str != null)
                    {
                        info.field.SetValue(instance, str);
                    }
                    break;

                case DataType2.Class:
                    if (info.OldFieldInfo.DBType == DataType2.Struct)
                    {
                        info.field.SetValue(instance, ReadStruct(info.typeInfo, fake, offset));
                    }
                    else
                    {
                        FakeStruct fs = fake.GetData <FakeStruct>(offset);
                        if (fs != null)
                        {
                            if (HaveDerived)
                            {
                                int a      = fake[offset];
                                int dbtype = a >> 16;
                                int index  = a & 0xffff;
                                var dt     = oldTypes[dbtype].NewType;
                                if (dt != null)
                                {
                                    info.field.SetValue(instance, ReadObject(dt, fs, index));
                                }
                                //else info.field.SetValue(instance, ReadObject(info.typeInfo, fs, index));
                            }
                            else
                            {
                                info.field.SetValue(instance, ReadObject(info.typeInfo, fs, fake[offset] & 0xffff));
                            }
                        }
                    }
                    break;

                case DataType2.Struct:
                    if (info.OldFieldInfo.DBType == DataType2.Class)
                    {
                        var fs = fake.GetData <FakeStruct>(offset);
                        if (fs != null)
                        {
                            info.field.SetValue(instance, ReadObject(info.typeInfo, fs, fake[offset] & 0xffff));
                        }
                    }
                    else
                    {
                        info.field.SetValue(instance, ReadStruct(info.typeInfo, fake, offset));
                    }
                    break;

                case DataType2.Boolean:
                    info.field.SetValue(instance, fake[offset] == 1);
                    break;
                }
            }
            else if (info.DBType < 64)
            {
                if (info.TypeName == DataType2.List)
                {
                    var list = ReadList(info, fake, offset);
                    info.field.SetValue(instance, list);
                }
                else
                {
                    info.field.SetValue(instance, ReadArray(info, fake, offset));
                }
            }
            else
            {
                if (info.TypeName == DataType2.List)
                {
                    info.field.SetValue(instance, ReadList2(info, fake, offset));
                }
                else
                {
                    info.field.SetValue(instance, ReadArray2(info, fake, offset));
                }
            }
        }
예제 #23
0
        void CompatibleReadValue(DataFieldInfo info, FakeStruct fake, int offset, object instance)
        {
            switch (info.DBType)
            {
            case DataType2.Byte:
                info.field.SetValue(instance, (byte)fake[offset]);
                break;

            case DataType2.SByte:
                info.field.SetValue(instance, (sbyte)fake[offset]);
                break;

            case DataType2.Int16:
                info.field.SetValue(instance, (Int16)fake[offset]);
                break;

            case DataType2.UInt16:
                info.field.SetValue(instance, (UInt16)fake[offset]);
                break;

            case DataType2.Int32:
            case DataType2.UInt32:
                info.field.SetValue(instance, fake[offset]);
                break;

            case DataType2.Float:
                info.field.SetValue(instance, fake.GetFloat(offset));
                break;

            case DataType2.Int64:
            case DataType2.UInt64:
                if (info.OldFieldInfo.DataLength == 4)
                {
                    info.field.SetValue(instance, fake[offset]);
                }
                else
                {
                    info.field.SetValue(instance, fake.GetInt64(offset));
                }
                break;

            case DataType2.Double:
                if (info.OldFieldInfo.DataLength == 4)
                {
                    info.field.SetValue(instance, fake.GetFloat(offset));
                }
                else
                {
                    info.field.SetValue(instance, fake.GetDouble(offset));
                }
                break;

            case DataType2.Decimal:
                if (info.OldFieldInfo.DataLength == 4)
                {
                    info.field.SetValue(instance, fake.GetFloat(offset));
                }
                else if (info.OldFieldInfo.DataLength == 8)
                {
                    info.field.SetValue(instance, fake.GetDouble(offset));
                }
                else
                {
                    info.field.SetValue(instance, fake.GetDecimal(offset));
                }
                break;
            }
        }
예제 #24
0
        void ReadField(FakeStruct fake, int start, DataFieldInfo info, IntPtr ptr)
        {
            int offset = start + info.OldFieldInfo.DataOffset;

            if (info.DBType < 11)
            {
                CompatibleReadValue(info, fake, offset, ptr);
            }
            else if (info.DBType < 32)
            {
                switch (info.DBType)
                {
                case DataType2.String:
                    string str = fake.GetData <string>(offset);
                    if (str != null)
                    {
                        UnsafeOperation.SetObject(ptr + info.MemOffset, str);
                    }
                    break;

                case DataType2.Class:
                    if (info.OldFieldInfo.DBType == DataType2.Struct)
                    {
                        UnsafeOperation.SetObject(ptr + info.MemOffset, ReadStructToObject(info.typeInfo, fake, offset));
                    }
                    else
                    {
                        FakeStruct fs = fake.GetData <FakeStruct>(offset);
                        if (fs != null)
                        {
                            if (HaveDerived)
                            {
                                int a      = fake[offset];
                                int dbtype = a >> 16;
                                int index  = a & 0xffff;
                                var dt     = oldTypes[dbtype].NewType;
                                if (dt != null)
                                {
                                    UnsafeOperation.SetObject(ptr + info.MemOffset, ReadObject(dt, fs, index));
                                }
                            }
                            else
                            {
                                UnsafeOperation.SetObject(ptr + info.MemOffset, ReadObject(info.typeInfo, fs, fake[offset] & 0xffff));
                            }
                        }
                    }
                    break;

                case DataType2.Struct:
                    if (info.OldFieldInfo.DBType == DataType2.Class)
                    {
                        var fs = fake.GetData <FakeStruct>(offset);
                        if (fs != null)
                        {
                            ReadStruct(info.typeInfo, fs, 0, ptr + info.MemOffset);
                        }
                    }
                    else
                    {
                        ReadStruct(info.typeInfo, fake, offset, ptr + info.MemOffset);
                    }
                    break;

                case DataType2.Boolean:
                    unsafe { *(byte *)(ptr + info.MemOffset) = (byte)fake[offset]; }
                    break;
                }
            }
            else if (info.DBType < 64)
            {
                if (info.TypeName == "List`1")
                {
                    UnsafeOperation.SetObject(ptr + info.MemOffset, ReadList(info, fake, offset));
                }
                else
                {
                    UnsafeOperation.SetObject(ptr + info.MemOffset, ReadArray(info, fake, offset));
                }
            }
            else
            {
                if (info.TypeName == "List`1")
                {
                    UnsafeOperation.SetObject(ptr + info.MemOffset, ReadList2(info, fake, offset));
                }
                else
                {
                    UnsafeOperation.SetObject(ptr + info.MemOffset, ReadArray2(info, fake, offset));
                }
            }
        }