GetReader() protected méthode

Gets a valid StreamReader that can be used to read CSV data. If we were configured with a StreamReader, it may be that one. If we are accessing a file we will open a new reader. You should not close it yourself, instead you should call DoneWithReader when you are done with it.
protected GetReader ( ClassMapping mapping ) : StreamReader
mapping ClassMapping The mapping for the object we intend to read.
Résultat System.IO.StreamReader
Exemple #1
0
        private static DataReaderConfig GetConfig(CsvDaLayer layer, ClassMapping mapping)
        {
            CsvDataReaderConfig retVal = new CsvDataReaderConfig();

            try
            {
                retVal.Reader = layer.GetReader(mapping);
                if (CsvDaLayer.UseNamedColumns(mapping))
                {
                    // If the CSV has row headers, read the header row.
                    IList colNameRow = ReadRawCsvRow(retVal.Reader);
                    for (int x = 0; x < colNameRow.Count; x++)
                    {
                        retVal.IndexesByName[colNameRow[x].ToString()] = x;
                    }
                }
                else
                {
                    // No row headers, so we must be mapped to column numbers.
                    // In that case, just map the column number strings to the ints.
                    foreach (string colStr in mapping.AllDataColsInOrder)
                    {
                        // Remember the mapping column numbers are 1-based but
                        // the internal column numbers are 0-based.
                        retVal.IndexesByName[colStr] = int.Parse(colStr) - 1;
                    }
                }
                return retVal;
            }
            catch (Exception e)
            {
                // Problem setting up, close the reader.
                if (retVal.Reader != null)
                {
                    layer.DoneWithReader(retVal.Reader);
                }
                throw new LoggingException("Unable to begin reading from CSV file.", e);
            }
        }