public object GetField(IDataRecord record, int recordIndex) { var fieldValue = inner.GetField(record, recordIndex); if (fieldValue is DBNull) { return(defaultValue); } return(fieldValue); }
public string GetField(IDataRecord record, int recordIndex) { try { return(inner.GetField(record, recordIndex).ToString()); } catch (Exception e) { var message = String.Format("Could not read column {0}: {1}", userFriendlyColumnName, e.Message); throw new SqlDataFormatUnexpectedException(message, e); } }
private static T GetField <T>(IFieldReader <T> reader, IDataRecord record, int recordIndex, IMappingField mappingField) { try { return(reader.GetField(record, recordIndex)); } catch (Exception e) { var message = String.Format("Could not read {0} of row {1}: {2}. It looks like the data for the {0} is incorrect. If you are importing data from Excel, please check the mapping for this column and try again.", mappingField.UserFriendlyName, recordIndex, e.Message); throw new SqlDataFormatUnexpectedException(message, e); } }
public T GetField(IDataRecord record, int recordIndex) { var fieldValue = inner.GetField(record, recordIndex); if (!(fieldValue is T)) { throw new SqlDataFormatUnexpectedException( String.Format("Unrecognised data schema. Value '{0}' from column {1} was {2}, expected {3}", fieldValue, userFriendlyColumnName, fieldValue.GetType(), typeof(T))); } return((T)fieldValue); }
public T GetField(IDataRecord record, int recordIndex) { var actualFieldName = record.GetName(index); if (actualFieldName != fieldName) { throw new SqlDataFormatUnexpectedException( String.Format("Unrecognised data schema. Column {0} was {1}, expected {2}", index, actualFieldName, fieldName)); } return(dataReader.GetField(record, recordIndex)); }
/// <summary> /// Reads a line of the CSV file. /// </summary> /// <returns>The CSV line.</returns> protected virtual string[] ReadLine() { context.RecordBuilder.Clear(); context.Row++; context.RawRow++; while (true) { context.C = fieldReader.GetChar(); if (context.C == -1) { // We have reached the end of the file. if (context.RecordBuilder.Length > 0) { // There was no line break at the end of the file. // We need to return the last record first. context.RecordBuilder.Add(fieldReader.GetField()); return(context.RecordBuilder.ToArray()); } return(null); } if (context.RecordBuilder.Length == 0 && ((context.C == context.ParserConfiguration.Comment && context.ParserConfiguration.AllowComments) || context.C == '\r' || context.C == '\n')) { ReadBlankLine(); if (!context.ParserConfiguration.IgnoreBlankLines) { break; } continue; } if (context.C == context.ParserConfiguration.Quote && !context.ParserConfiguration.IgnoreQuotes) { if (ReadQuotedField()) { break; } } else { if (ReadField()) { break; } } } return(context.RecordBuilder.ToArray()); }
public DateTime GetField(IDataRecord record, int recordIndex) { var value = inner.GetField(record, recordIndex); if (value is DateTime) { return((DateTime)value); } DateTime dateTimeParse; if (value is string && DateTime.TryParse(value as string, out dateTimeParse)) { return(dateTimeParse); } if (value is double) { return(DateTime.FromOADate((double)value)); } throw new SqlDataFormatUnexpectedException(String.Format("Could not interpret value '{0}' from column {1} as a date", value, userFriendlyColumnName)); }
/// <summary> /// Reads a line of the CSV file. /// </summary> /// <returns>The CSV line.</returns> protected virtual string[] ReadLine() { context.RecordBuilder.Clear(); context.Row++; context.RawRow++; while (true) { if (fieldReader.IsBufferEmpty && !fieldReader.FillBuffer()) { // End of file. if (context.RecordBuilder.Length > 0) { // There was no line break at the end of the file. // We need to return the last record first. context.RecordBuilder.Add(fieldReader.GetField()); return(context.RecordBuilder.ToArray()); } return(null); } context.C = fieldReader.GetChar(); if (context.RecordBuilder.Length == 0 && ((context.C == context.ParserConfiguration.Comment && context.ParserConfiguration.AllowComments) || context.C == '\r' || context.C == '\n')) { ReadBlankLine(); if (!context.ParserConfiguration.IgnoreBlankLines) { break; } continue; } // Trim start outside of quotes. if (context.C == ' ' && (context.ParserConfiguration.TrimOptions & TrimOptions.Trim) == TrimOptions.Trim) { ReadSpaces(); fieldReader.SetFieldStart(-1); } if (context.C == context.ParserConfiguration.Quote && !context.ParserConfiguration.IgnoreQuotes) { if (ReadQuotedField()) { break; } } else { if (ReadField()) { break; } } } return(context.RecordBuilder.ToArray()); }
public TOut GetField(IDataRecord record, int recordIndex) { return(lookup.GetLookupValue(innerReader.GetField(record, recordIndex))); }