public static DbcSchema Load(Stream source, int specifiedColumns) { XDocument doc = XDocument.Load(source); DbcSchema result = new DbcSchema(); foreach (var e in doc.Root.Elements("Column")) { string name = e.Attribute("Name").Value; int pos = int.Parse(e.Attribute("Position").Value); ColumnType type = (ColumnType)Enum.Parse(typeof(ColumnType), e.Attribute("Type").Value, true); int width = int.Parse(e.Attribute("Width").Value); var col = new DbcColumnSchema() { Position = pos, Name = name, Type = type, Width = width, }; result.AddColumn(col); } while (result.ColumnCount > specifiedColumns) { result._columns.RemoveAt(result.ColumnCount - 1); } while (result._columns.Count < specifiedColumns) { var col = new DbcColumnSchema() { Position = result.ColumnCount, Name = "Column" + result.ColumnCount, Type = ColumnType.Int32, Width = 100, }; result.AddColumn(col); } return(result); }
private void CreateDefaultSchema() { _schema = new DbcSchema(); for (int i = 0; i < _table.ColumnCount; i++) { var col = new DbcColumnSchema() { Name = "Column" + i, Position = i, Type = ColumnType.Int32, Width = 100, }; _schema.AddColumn(col); } BindSchema(); }
public static DbcSchema Load(Stream source, int specifiedColumns) { XDocument doc = XDocument.Load(source); DbcSchema result = new DbcSchema(); foreach (var e in doc.Root.Elements("Column")) { string name = e.Attribute("Name").Value; int pos = int.Parse(e.Attribute("Position").Value); ColumnType type = (ColumnType)Enum.Parse(typeof(ColumnType), e.Attribute("Type").Value, true); int width = int.Parse(e.Attribute("Width").Value); var col = new DbcColumnSchema() { Position = pos, Name = name, Type = type, Width = width, }; result.AddColumn(col); } while (result.ColumnCount > specifiedColumns) result._columns.RemoveAt(result.ColumnCount - 1); while (result._columns.Count < specifiedColumns) { var col = new DbcColumnSchema() { Position = result.ColumnCount, Name = "Column" + result.ColumnCount, Type = ColumnType.Int32, Width = 100, }; result.AddColumn(col); } return result; }