public bool ReadRow(IDataRow row, Dictionary <int, int> charactersLength = null) { row.Clear(); m_lineNbr++; if (reader.Read()) { for (int i = 0; i < reader.FieldCount; i++) { int?itemLength = null; if (charactersLength != null && charactersLength.ContainsKey(i + 1)) { itemLength = charactersLength[i + 1]; } var value = Convert.ToString(reader.GetValue(i)); if (value != null && itemLength.HasValue && itemLength.Value != 0 && value.Length > itemLength.Value) { value = value.Substring(0, itemLength.Value - 1); } row.Add(new DataRowItem(value, m_lineNbr)); } return(true); } else { return(false); } }
/// <param name="row"> /// Contains the values in the current row, in the order in which they /// appear in the file. /// </param> /// <returns> /// True if a row was returned in parameter "row". /// False if no row returned. In that case, you're at the end of the file. /// </returns> public bool ReadRow(IDataRow row, List <int> charactersLength = null) { row.Clear(); var i = 0; while (true) { // Number of the line where the item starts. Note that an item // can span multiple lines. var startingLineNbr = LineNbr; string item = null; var itemLength = charactersLength == null ? (int?)null : charactersLength.Skip(i).First(); var moreAvailable = _line.GetNextItem(ref item, itemLength); if (charactersLength != null) { if (!(charactersLength.Count() > i + 1)) { if (moreAvailable) { row.Add(new DataRowItem(item, startingLineNbr)); } if (!_line.Eol) { //line.AdvanceToEndOfLine(); moreAvailable = false; } } } if (!moreAvailable) { return(row.Count > 0); } row.Add(new DataRowItem(item, startingLineNbr)); i++; } }
public bool ReadRow(ref IDataRow row) { row.Clear(); while (true) { int startingLineNbr = m_lineNbr; string item = null; bool moreAvailable = GetNextItem(ref item); if (!moreAvailable) { return(row.Count > 0); } row.Add(new DataRowItem(item, startingLineNbr)); } }
/// /////////////////////////////////////////////////////////////////////// /// ReadRow /// /// <summary> /// /// </summary> /// <param name="row"> /// Contains the values in the current row, in the order in which they /// appear in the file. /// </param> /// <returns> /// True if a row was returned in parameter "row". /// False if no row returned. In that case, you're at the end of the file. /// </returns> public bool ReadRow(ref IDataRow row) { row.Clear(); while (true) { // Number of the line where the item starts. Note that an item // can span multiple lines. int startingLineNbr = m_lineNbr; string item = null; bool moreAvailable = GetNextItem(ref item); if (!moreAvailable) { return(row.Count > 0); } row.Add(new DataRowItem(item, startingLineNbr)); } }
/// /////////////////////////////////////////////////////////////////////// /// ReadRow /// /// <summary> /// /// </summary> /// <param name="row"> /// Contains the values in the current row, in the order in which they /// appear in the file. /// </param> /// <returns> /// True if a row was returned in parameter "row". /// False if no row returned. In that case, you're at the end of the file. /// </returns> public bool ReadRow(ref IDataRow row) { row.Clear(); while (true) { // Number of the line where the item starts. Note that an item // can span multiple lines. int startingLineNbr = m_lineNbr; string item = null; bool moreAvailable = GetNextItem(ref item); if (!moreAvailable) { return (row.Count > 0); } row.Add(new DataRowItem(item, startingLineNbr)); } }
/// /////////////////////////////////////////////////////////////////////// /// ReadRow /// /// <summary> /// /// </summary> /// <param name="row"> /// Contains the values in the current row, in the order in which they /// appear in the file. /// </param> /// <returns> /// True if a row was returned in parameter "row". /// False if no row returned. In that case, you're at the end of the file. /// </returns> public bool ReadRow(IDataRow row, List<int> charactersLength = null) { row.Clear(); int i = 0; while (true) { // Number of the line where the item starts. Note that an item // can span multiple lines. int startingLineNbr = m_lineNbr; string item = null; int? itemLength = charactersLength == null ? (int?)null : charactersLength.Skip(i).First(); bool moreAvailable = GetNextItem(ref item, itemLength); if (charactersLength != null) { if (!(charactersLength.Count > i + 1)) { if (moreAvailable) { row.Add(new DataRowItem(item, startingLineNbr)); } if (!EOL) { AdvanceToEndOfLine(); moreAvailable = false; } } } if (!moreAvailable) { return (row.Count > 0); } row.Add(new DataRowItem(item, startingLineNbr)); i++; } }