示例#1
0
        static private void readData(object obj, FieldInfo fInfo, DataOffsetAttribute attr, byte[] data, int offset)
        {
            offset += attr.Offset;
            IDataIO idata = fInfo.GetValue(obj) as IDataIO;

            if (idata != null)
            {
                idata.Read(data, offset);
            }
            else
            {
                switch (attr.Type)
                {
                case DataType.SByte:
                    fInfo.SetValue(obj, (sbyte)data[offset]);
                    break;

                case DataType.IByte:
                    fInfo.SetValue(obj, data[offset]);
                    break;

                case DataType.Byte:
                    fInfo.SetValue(obj, data[offset]);
                    break;

                case DataType.SWord:
                {
                    short s = (short)(data[offset] + (data[offset + 1] << 8));
                    fInfo.SetValue(obj, s);
                }
                break;

                case DataType.Word:
                {
                    ushort w = (ushort)(data[offset] + (data[offset + 1] << 8));
                    fInfo.SetValue(obj, w);
                }
                break;

                case DataType.Int:
                {
                    int i = data[offset] + (data[offset + 1] << 8) + (data[offset + 2] << 16) + (data[offset + 3] << 24);
                    fInfo.SetValue(obj, i);
                }
                break;

                case DataType.Bool:
                    fInfo.SetValue(obj, (data[offset] != 0));
                    break;

                case DataType.ByteArray:
                {
                    byte[] a = new byte[attr.Size];

                    System.Array.Copy(data, offset, a, 0, attr.Size);
                    fInfo.SetValue(obj, a);
                }
                break;

                case DataType.ShortArray:
                {
                    short[] a = new short[attr.Size];
                    for (int i = 0; i < attr.Size; i++)
                    {
                        a[i] = (short)(data[offset + (i * 2)] + (data[offset + 1 + (i * 2)] << 8));
                    }
                    fInfo.SetValue(obj, a);
                }
                break;

                case DataType.WordArray:
                {
                    ushort[] a = new ushort[attr.Size];
                    for (int i = 0; i < attr.Size; i++)
                    {
                        a[i] = (ushort)(data[offset + (i * 2)] + (data[offset + 1 + (i * 2)] << 8));
                    }
                    fInfo.SetValue(obj, a);
                }
                break;

                case DataType.PString:
                {
                    fInfo.SetValue(obj, Sys.ArrayToString(data, offset, attr.Size));
                }
                break;

                case DataType.Cust1Array:
                {
                    StatValue[] sv = new StatValue[attr.Size];
                    for (int i = 0; i < attr.Size; i++)
                    {
                        sv[i].cur  = data[offset++];
                        sv[i].full = data[offset++];
                    }
                    fInfo.SetValue(obj, sv);
                }
                break;

                default:
                    throw new NotImplementedException();
                }
            }
        }
示例#2
0
 internal void Load()
 {
     _pairWrapper = _dataIO.Read();
 }