示例#1
0
        /// <summary>
        /// Adds the field to the current record.
        /// </summary>
        /// <param name="recordPosition">The record position to add the field to.</param>
        /// <param name="field">The field to add.</param>
        protected virtual void AddFieldToRecord(ref int recordPosition, string field, ref bool fieldIsBad)
        {
            if (record.Length < recordPosition + 1)
            {
                // Resize record if it's too small.
                Array.Resize(ref record, recordPosition + 1);

                // Set the field count. If there is a header
                // record, then we can go by the number of
                // headers there is. If there is no header
                // record, then we can go by the first row.
                // Either way, we're using the first row.
                if (currentRow == 1)
                {
                    FieldCount = record.Length;
                }
            }

            if (fieldIsBad && configuration.ThrowOnBadData)
            {
                throw new CsvBadDataException(string.Format("Field: '{0}'", field));
            }

            if (fieldIsBad && configuration.BadDataCallback != null)
            {
                configuration.BadDataCallback(field);
            }

            fieldIsBad = false;

            record[recordPosition] = field;
            recordPosition++;
        }
示例#2
0
 /// <summary>
 ///     Adds the field to the current record.
 /// </summary>
 /// <param name="recordPosition">The record position to add the field to.</param>
 /// <param name="field">The field to add.</param>
 protected virtual void AddFieldToRecord(ref int recordPosition, string field, ref bool fieldIsBad)
 {
     if (record.Length < recordPosition + 1)
     {
         Array.Resize(ref record, recordPosition + 1);
         if (currentRow == 1)
         {
             FieldCount = record.Length;
         }
     }
     if (fieldIsBad && configuration.ThrowOnBadData)
     {
         throw new CsvBadDataException(string.Format("Field: '{0}'", field));
     }
     if (fieldIsBad && configuration.BadDataCallback != null)
     {
         configuration.BadDataCallback(field);
     }
     fieldIsBad             = false;
     record[recordPosition] = field;
     recordPosition         = recordPosition + 1;
 }