예제 #1
0
        protected IEnumerator <T> GetEnumerator <T>()
            where T : KeyStringDictionary, new()
        {
            Info.Refresh();
            if (!Info.Exists)
            {
                yield break;
            }

            using (var stream = Info.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (var reader = new TsvStreamReader(stream))
                {
                    while (!reader.EndOfStream)
                    {
                        var entry = reader.ReadEntry <T>();
                        if (null == entry)
                        {
                            break;
                        }

                        yield return((T)entry);
                    }
                }
            }
        }
예제 #2
0
        public void op_ReadEntry_whenColumnsCtor()
        {
            var headers = new[]
            {
                "A", "B"
            };

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.WriteLine("1A\t1B");
                    writer.Flush();
                    stream.Position = 0;
                    using (var reader = new TsvStreamReader(stream, headers))
                    {
                        var actual = reader.ReadEntry();
                        Assert.Equal("A\tB", reader.Header);
                        Assert.Equal(1, reader.LineNumber);
                        Assert.Equal(1, reader.EntryNumber);
                        Assert.Equal("1A", actual["A"]);
                        Assert.Equal("1B", actual["B"]);
                    }
                }
            }
        }
예제 #3
0
 public void op_ReadEntry_whenUnixLF()
 {
     using (var stream = new MemoryStream())
     {
         using (var writer = new StreamWriter(stream))
         {
             writer.WriteLine("A\tB\n1A\t1B");
             writer.Flush();
             stream.Position = 0;
             using (var reader = new TsvStreamReader(stream))
             {
                 var actual = reader.ReadEntry();
                 Assert.Equal(2, reader.LineNumber);
                 Assert.Equal(1, reader.EntryNumber);
                 Assert.Equal("1A", actual["A"]);
                 Assert.Equal("1B", actual["B"]);
             }
         }
     }
 }
예제 #4
0
        public void op_ReadEntry_whenMissingColumnItem()
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.WriteLine("A\tB\tC");
                    writer.WriteLine("1\t2");
                    writer.Flush();
                    stream.Position = 0;
                    using (var reader = new TsvStreamReader(stream))
                    {
                        // ReSharper disable AccessToDisposedClosure
                        Assert.Throws <FormatException>(() => reader.ReadEntry());

                        // ReSharper restore AccessToDisposedClosure
                    }
                }
            }
        }
예제 #5
0
 public void op_ReadEntry_whenTrailingNewLine()
 {
     using (var stream = new MemoryStream())
     {
         using (var writer = new StreamWriter(stream))
         {
             writer.WriteLine("A\tB");
             writer.WriteLine("1A\t1B");
             writer.WriteLine(string.Empty);
             writer.Flush();
             stream.Position = 0;
             using (var reader = new TsvStreamReader(stream))
             {
                 reader.ReadEntry();
                 var actual = reader.ReadEntry();
                 Assert.Equal(3, reader.LineNumber);
                 Assert.Equal(1, reader.EntryNumber);
                 Assert.Null(actual);
             }
         }
     }
 }
예제 #6
0
        public void op_ReadEntry_whenHeaderCtor()
        {
            const string header = "A\tB";

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.WriteLine("1A\t1B");
                    writer.Flush();
                    stream.Position = 0;
                    using (var reader = new TsvStreamReader(stream, header))
                    {
                        Assert.Equal(header, reader.Header);
                        var actual = reader.ReadEntry();
                        Assert.Equal(1, reader.LineNumber);
                        Assert.Equal(1, reader.EntryNumber);
                        Assert.Equal("1A", actual["A"]);
                        Assert.Equal("1B", actual["B"]);
                    }
                }
            }
        }