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


C# CsvRecordReader.GetFieldHeaders方法代码示例

本文整理汇总了C#中CsvRecordReader.GetFieldHeaders方法的典型用法代码示例。如果您正苦于以下问题:C# CsvRecordReader.GetFieldHeaders方法的具体用法?C# CsvRecordReader.GetFieldHeaders怎么用?C# CsvRecordReader.GetFieldHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CsvRecordReader的用法示例。


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

示例1: 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

示例2: GetFieldHeaders_WithEmptyHeaderNames

        public void GetFieldHeaders_WithEmptyHeaderNames(string defaultHeaderName)
        {
            if (defaultHeaderName == null)
                defaultHeaderName = "Column";

            using (var csv = new CsvRecordReader(new StringReader(",  ,,aaa,\"   \",,,"), true))
            {
                csv.DefaultHeaderName = defaultHeaderName;

                Assert.IsNull(csv.Read());
                Assert.AreEqual(8, csv.FieldCount);

                var headers = csv.GetFieldHeaders();
                Assert.AreEqual(csv.FieldCount, headers.Length);

                Assert.AreEqual("aaa", headers[3]);
                foreach (var index in new int[] { 0, 1, 2, 4, 5, 6, 7 })
                    Assert.AreEqual(defaultHeaderName + index.ToString(), headers[index]);
            }
        }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:20,代码来源:CsvReaderTest.cs

示例3: GetFieldHeadersTest_EmptyCsv

        public void GetFieldHeadersTest_EmptyCsv()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader("#asdf\n\n#asdf,asdf"), true))
            {
                var headers = csv.GetFieldHeaders();

                Assert.IsNotNull(headers);
                Assert.AreEqual(0, headers.Length);
            }
        }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:10,代码来源:CsvReaderTest.cs

示例4: GetFieldHeadersTest2

        public void GetFieldHeadersTest2()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleData1), true))
            {
                var headers = csv.GetFieldHeaders();

                Assert.IsNotNull(headers);
                Assert.AreEqual(CsvReaderSampleData.SampleData1RecordCount, headers.Length);

                Assert.AreEqual(CsvReaderSampleData.SampleData1Header0, headers[0]);
                Assert.AreEqual(CsvReaderSampleData.SampleData1Header1, headers[1]);
                Assert.AreEqual(CsvReaderSampleData.SampleData1Header2, headers[2]);
                Assert.AreEqual(CsvReaderSampleData.SampleData1Header3, headers[3]);
                Assert.AreEqual(CsvReaderSampleData.SampleData1Header4, headers[4]);
                Assert.AreEqual(CsvReaderSampleData.SampleData1Header5, headers[5]);

                Assert.AreEqual(0, headers.GetFieldIndex(CsvReaderSampleData.SampleData1Header0));
                Assert.AreEqual(1, headers.GetFieldIndex(CsvReaderSampleData.SampleData1Header1));
                Assert.AreEqual(2, headers.GetFieldIndex(CsvReaderSampleData.SampleData1Header2));
                Assert.AreEqual(3, headers.GetFieldIndex(CsvReaderSampleData.SampleData1Header3));
                Assert.AreEqual(4, headers.GetFieldIndex(CsvReaderSampleData.SampleData1Header4));
                Assert.AreEqual(5, headers.GetFieldIndex(CsvReaderSampleData.SampleData1Header5));
            }
        }
开发者ID:paulecoyote,项目名称:CsvReader,代码行数:24,代码来源:CsvReaderTest.cs

示例5: GetFieldHeadersTest1

        public void GetFieldHeadersTest1()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleData1), false))
            {
                var headers = csv.GetFieldHeaders();

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


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