示例#1
0
        public static DataTable DeserializeDataTable(BinaryTypesReader br)
        {
            DataTable table = new DataTable();

            table.TableName = br.ReadString();

            int columnCount = br.Read7BitInt();

            Type[] columnTypes = new Type[columnCount];

            for (int i = 0; i < columnCount; i++)
            {
                string columnName = br.ReadString();
                string typeName   = br.ReadString();
                Type   columnType = Type.GetType(typeName);

                DataColumn col = new DataColumn(columnName, columnType);
                table.Columns.Add(col);

                columnTypes[i] = columnType;
            }

            int rowsCount = br.Read7BitInt();

            for (int rowIndex = 0; rowIndex < rowsCount; rowIndex++)
            {
                DataRow row = table.NewRow();
                table.Rows.Add(row);

                for (int i = 0; i < columnCount; i++)
                {
                    if (columnTypes[i] == typeof(System.String))
                    {
                        row[i] = br.ReadString();
                    }
                    else if (columnTypes[i] == typeof(System.Int32))
                    {
                        row[i] = br.Read7BitInt();
                    }
                    else if (columnTypes[i] == typeof(System.Int64))
                    {
                        row[i] = br.Read7BitLong();
                    }
                    else if (columnTypes[i] == typeof(System.Decimal))
                    {
                        row[i] = br.ReadCompactDecimal();
                    }
                    else if (columnTypes[i] == typeof(System.DateTime))
                    {
                        row[i] = br.ReadCompactDateTime(TimeSpan.TicksPerMillisecond * 100);
                    }
                    else if (columnTypes[i] == typeof(bool))
                    {
                        row[i] = br.ReadBoolean();
                    }
                }
            }

            return(table);
        }
示例#2
0
        public static void DeserializeList <T>(BinaryTypesReader br, List <T> list, ReadDataDelegate <T> itemReader, object objParam)
        {
            //Clear the list before work starts. In case the list is null it will throw exception
            list.Clear();
            int count = br.Read7BitInt();

            for (int i = 0; i < count; i++)
            {
                T item = itemReader(br, objParam);
                list.Add(item);
            }
        }
示例#3
0
        public static void DeserializeDictionary <K, V>(
            BinaryTypesReader br,
            IDictionary <K, V> map,
            ReadDataDelegate <K> keyReader,
            object keyObjParam,
            ReadDataDelegate <V> valReader,
            object valObjParam)
        {
            int count = br.Read7BitInt();

            for (int i = 0; i < count; i++)
            {
                K key = keyReader(br, keyObjParam);
                V val = valReader(br, valObjParam);
                map.Add(key, val);
            }
        }
示例#4
0
        ///////////////////////////////////////////////////////////////////////

        public static int ReadInt(BinaryTypesReader br, object objParam)
        {
            return(br.Read7BitInt());
        }