/// <summary> /// DataTable拆包 /// </summary> /// <param name="value"></param> /// <returns></returns> public unsafe static DataTable Get(dataTable value) { if (value == null) { return(null); } DataTable table = new DataTable(value.name); try { if (value.rowCount != 0) { fixed(byte *dataFixed = value.data.Data) { dataReader builder = new dataReader(dataFixed, value.data.Strings, value.data.Bytes); value.get(table, builder); } } return(table); } catch (Exception error) { table.Dispose(); log.Error.Add(error, null, false); } return(null); }
/// <summary> /// DataTable拆包 /// </summary> /// <param name="table"></param> /// <param name="builder">数据对象拆包器</param> private unsafe void get(DataTable table, dataReader builder) { int index = 0; DataColumn[] columns = new DataColumn[columnNames.Length]; fixed(byte *columnFixed = columnTypes) { byte *columnIndex = columnFixed; foreach (string columnName in columnNames) { columns[index++] = new DataColumn(columnName, *columnIndex < types.Length ? types[*columnIndex] : typeof(object)); ++columnIndex; } table.Columns.AddRange(columns); fixed(byte *nullFixed = dbNull) { fixedMap nullMap = new fixedMap(nullFixed); for (index = 0; rowCount != 0; --rowCount) { object[] values = new object[columnNames.Length]; columnIndex = columnFixed; for (int valueIndex = 0; valueIndex != columnNames.Length; ++valueIndex) { values[valueIndex] = nullMap.Get(index++) ? DBNull.Value : builder.Get(*columnIndex); ++columnIndex; } DataRow row = table.NewRow(); row.ItemArray = values; table.Rows.Add(row); } } } }
/// <summary> /// DataSet拆包 /// </summary> /// <param name="set"></param> private unsafe void set(DataSet set) { if (tables.length() != 0) { fixed(byte *dataFixed = data.Data) { dataReader builder = new dataReader(dataFixed, data.Strings, data.Bytes); foreach (dataTable table in tables) { set.Tables.Add(table.Get(builder)); } } } }
/// <summary> /// DataTable拆包 /// </summary> /// <param name="builder">数据对象拆包器</param> /// <returns></returns> internal DataTable Get(dataReader builder) { DataTable table = new DataTable(name); if (rowCount != 0) { try { get(table, builder); } catch (Exception error) { table.Dispose(); table = null; log.Error.Add(error, null, false); } } return(table); }