/// <summary> /// Adds a column to the schema, using the given definition to define it. /// </summary> /// <param name="definition">The definition of the column to add.</param> /// <param name="window">Describes the column</param> /// <returns>The current schema.</returns> public FixedLengthSchema AddColumn(ColumnDefinition definition, Window window) { if (window == null) { throw new ArgumentNullException("window"); } schema.AddColumn(definition); windows.Add(window); totalWidth += window.Width; return this; }
/// <summary> /// Adds a column to the schema, using the given definition to define it. /// </summary> /// <param name="definition">The definition of the column to add.</param> /// <returns>The current schema.</returns> public SeparatedValueSchema AddColumn(ColumnDefinition definition) { if (definition == null) { throw new ArgumentNullException("definition"); } if (ordinals.ContainsKey(definition.ColumnName)) { throw new ArgumentException(Resources.DuplicateColumnName, "definition"); } addColumn(definition); return this; }
private void addColumn(ColumnDefinition definition) { definitions.Add(definition); ordinals.Add(definition.ColumnName, definitions.Count - 1); }
private static object parseValue(ColumnDefinition definition, object value) { // Let the definition interpret nulls. if (value == null) { return definition.Parse(null); } // If the value is a string, give the parser a chance to interpret it. string asString = value as String; if (asString != null) { return definition.Parse(asString); } // If the value's type differs from the expected type, // convert it to a string and try to interpret it. if (value.GetType() != definition.ColumnType) { return Convert.ChangeType(value, definition.ColumnType); } // Otherwise, the type of the value matches the expected type. return value; }