当前位置: 首页>>代码示例>>C#>>正文


C# CsvRecordReader类代码示例

本文整理汇总了C#中CsvRecordReader的典型用法代码示例。如果您正苦于以下问题:C# CsvRecordReader类的具体用法?C# CsvRecordReader怎么用?C# CsvRecordReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CsvRecordReader类属于命名空间,在下文中一共展示了CsvRecordReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetBytesTest

        public void GetBytesTest()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleTypedData1), true))
            {

                Char[] temp = "abc".ToCharArray();
                Byte[] value = new Byte[temp.Length];

                for (int i = 0; i < temp.Length; i++)
                    value[i] = Convert.ToByte(temp[i]);

                foreach (IDataRecord reader in csv)
                {
                    Byte[] csvValue = new Byte[value.Length];

                    long count = reader.GetBytes(reader.GetOrdinal(typeof(String).FullName), 0, csvValue, 0, value.Length);

                    Assert.AreEqual(value.Length, count);
                    Assert.AreEqual(value.Length, csvValue.Length);

                    for (int i = 0; i < value.Length; i++)
                        Assert.AreEqual(value[i], csvValue[i]);
                }
            }
        }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:25,代码来源:CsvReaderIDataReaderTest.cs

示例2: CheckSampleData1

        public static void CheckSampleData1(CsvRecordReader csv)
        {
            Assert.AreEqual(CsvReaderSampleData.SampleData1FieldCount, csv.FieldCount);

            if (csv.HasHeaders)
            {
                var headers = csv.GetFieldHeaders();
                Assert.AreEqual(0, headers.GetFieldIndex(SampleData1Header0));
                Assert.AreEqual(1, headers.GetFieldIndex(SampleData1Header1));
                Assert.AreEqual(2, headers.GetFieldIndex(SampleData1Header2));
                Assert.AreEqual(3, headers.GetFieldIndex(SampleData1Header3));
                Assert.AreEqual(4, headers.GetFieldIndex(SampleData1Header4));
                Assert.AreEqual(5, headers.GetFieldIndex(SampleData1Header5));
            }

            Assert.AreEqual(-1, csv.CurrentRecordIndex);

            int recordCount = 0;

            foreach (CsvRecord record in csv)
            {
                CheckSampleData1(csv.HasHeaders, csv.CurrentRecordIndex, record.ToArray());
                recordCount++;
            }

            if (csv.HasHeaders)
                Assert.AreEqual(CsvReaderSampleData.SampleData1RecordCount, recordCount);
            else
                Assert.AreEqual(CsvReaderSampleData.SampleData1RecordCount + 1, recordCount);
        }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:30,代码来源:CsvReaderSampleData.cs

示例3: ArgumentTestIndexer2

 public void ArgumentTestIndexer2()
 {
     using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleData1), false))
     {
         string s = csv.Read()[CsvReaderSampleData.SampleData1RecordCount];
     }
 }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:7,代码来源:CsvReaderTest.cs

示例4: FieldCountTest

 public void FieldCountTest()
 {
     using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleData1), true))
     {
         Assert.AreEqual(CsvReaderSampleData.SampleData1RecordCount, csv.FieldCount);
     }
 }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:7,代码来源:CsvReaderIDataReaderTest.cs

示例5: ArgumentTestIndexer1

 public void ArgumentTestIndexer1()
 {
     using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleData1), false))
     {
         record = csv.Read();
         string s = record[-1];
     }
 }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:8,代码来源:CsvReaderTest.cs

示例6: GetBooleanTest

        public void GetBooleanTest()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleTypedData1), true))
            {

                Boolean value = true;
                foreach (IDataRecord reader in csv)
                {
                    Assert.AreEqual(value, reader.GetBoolean(reader.GetOrdinal(typeof(Boolean).FullName)));
                }
            }
        }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:12,代码来源:CsvReaderIDataReaderTest.cs

示例7: GetGuidTest

        public void GetGuidTest()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleTypedData1), true))
            {

                Guid value = new Guid("{11111111-1111-1111-1111-111111111111}");
                foreach (IDataRecord reader in csv)
                {
                    Assert.AreEqual(value, reader.GetGuid(reader.GetOrdinal(typeof(Guid).FullName)));
                }
            }
        }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:12,代码来源:CsvReaderIDataReaderTest.cs

示例8: GetFieldTypeTest

        public void GetFieldTypeTest()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleTypedData1), true))
            {

                foreach (IDataRecord reader in csv)
                {
                    for (int i = 0; i < reader.FieldCount; i++)
                        Assert.AreEqual(typeof(string), reader.GetFieldType(i));
                }
            }
        }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:12,代码来源:CsvReaderIDataReaderTest.cs

示例9: GetDecimalTest

        public void GetDecimalTest()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleTypedData1), true))
            {

                Decimal value = 1;
                foreach (IDataRecord reader in csv)
                {
                    Assert.AreEqual(value, reader.GetDecimal(reader.GetOrdinal(typeof(Decimal).FullName)));
                }
            }
        }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:12,代码来源:CsvReaderIDataReaderTest.cs

示例10: ParsingTest35

        public void ParsingTest35()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader("\t"), false, '\t'))
            {
                Assert.AreEqual(2, csv.FieldCount);

                record = csv.Read(); Assert.NotNull(record);

                Assert.AreEqual(string.Empty, record[0]);
                Assert.AreEqual(string.Empty, record[1]);

                Assert.IsNull(csv.Read());
            }
        }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:14,代码来源:CsvReaderTest.cs

示例11: ParsingTest38

        public void ParsingTest38()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader("abc,def,ghi\n"), false))
            {
                int fieldCount = csv.FieldCount;

                record = csv.Read(); Assert.NotNull(record);
                Assert.AreEqual("abc", record[0]);
                Assert.AreEqual("def", record[1]);
                Assert.AreEqual("ghi", record[2]);

                Assert.IsNull(csv.Read());
            }
        }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:14,代码来源:CsvReaderTest.cs

示例12: ParsingTest7

 public void ParsingTest7()
 {
     using (CsvRecordReader csv = new CsvRecordReader(new System.IO.StringReader("\r\n1\r\n"), false))
     {
         record = csv.Read(); Assert.NotNull(record);
         Assert.AreEqual(',', csv.Delimiter);
         Assert.AreEqual(0, csv.CurrentRecordIndex);
         Assert.AreEqual(1, csv.FieldCount);
         Assert.AreEqual("1", record[0]);
         Assert.IsNull(csv.Read());
     }
 }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:12,代码来源:CsvReaderTest.cs

示例13: GetStringTest

        public void GetStringTest()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleTypedData1), true))
            {

                String value = "abc";
                foreach (IDataRecord reader in csv)
                {
                    Assert.AreEqual(value, reader.GetString(reader.GetOrdinal(typeof(String).FullName)));
                }
            }
        }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:12,代码来源:CsvReaderIDataReaderTest.cs

示例14: ParsingTest41

        public void ParsingTest41()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader("First record          ,Second record"), false, CsvReader.DefaultDelimiter, CsvReader.DefaultQuote, CsvReader.DefaultEscape, CsvReader.DefaultComment, ValueTrimmingOptions.UnquotedOnly, 16))
            {
                Assert.AreEqual(2, csv.FieldCount);

                record = csv.Read(); Assert.NotNull(record);
                Assert.AreEqual("First record", record[0]);
                Assert.AreEqual("Second record", record[1]);

                Assert.IsNull(csv.Read());
            }
        }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:13,代码来源:CsvReaderTest.cs

示例15: ParsingTest42

 public void ParsingTest42()
 {
     using (var csv = new CsvRecordReader(new StringReader(" "), false))
     {
         record = csv.Read(); Assert.NotNull(record);
         Assert.AreEqual(1, csv.FieldCount);
         Assert.AreEqual(string.Empty, record[0]);
         Assert.IsNull(csv.Read());
     }
 }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:10,代码来源:CsvReaderTest.cs


注:本文中的CsvRecordReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。