Skip to content

Commit 4dbfd8f

Browse files
Merge pull request #21 from adamfisher/master
Added StreamReader.SkipLines() extension method.
2 parents b94c79e + 7573954 commit 4dbfd8f

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Description: C# Extension Methods Library to enhances the .NET Framework by adding hundreds of new methods. It drastically increases developers productivity and code readability. Support C# and VB.NET
2+
// Website & Documentation: https://github.com/zzzprojects/Z.ExtensionMethods
3+
// Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues
4+
// License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE
5+
// More projects: http://www.zzzprojects.com/
6+
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
7+
using System.IO;
8+
9+
public static partial class Extensions
10+
{
11+
/// <summary>
12+
/// Skips the specified number of lines in a stream reader based on its current position.
13+
/// </summary>
14+
/// <param name="this">The stream reader.</param>
15+
/// <param name="skipCount">The number of lines to skip.</param>
16+
public static void SkipLines(this StreamReader @this, int skipCount)
17+
{
18+
for (var i = 0; i < skipCount && !@this.EndOfStream; i++)
19+
{
20+
@this.ReadLine();
21+
}
22+
}
23+
}

src/Z.IO/Z.IO.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<Compile Include="System.IO.FileInfo\FileInfo.WriteAllBytes.cs" />
111111
<Compile Include="System.IO.FileInfo\FileInfo.WriteAllLines.cs" />
112112
<Compile Include="System.IO.FileInfo\FileInfo.WriteAllText.cs" />
113+
<Compile Include="System.IO.StreamReader\StreamReader.SkipLines.cs" />
113114
<Compile Include="System.IO.Stream\Stream.ReadToEnd.cs" />
114115
<Compile Include="System.IO.Stream\Stream.ToByteArray.cs" />
115116
<Compile Include="System.IO.Stream\Stream.ToMD5Hash.cs" />
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Description: C# Extension Methods Library to enhances the .NET Framework by adding hundreds of new methods. It drastically increases developers productivity and code readability. Support C# and VB.NET
2+
// Website & Documentation: https://github.com/zzzprojects/Z.ExtensionMethods
3+
// Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues
4+
// License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE
5+
// More projects: http://www.zzzprojects.com/
6+
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
7+
using System;
8+
using System.IO;
9+
using Microsoft.VisualStudio.TestTools.UnitTesting;
10+
11+
namespace Z.IO.Test
12+
{
13+
[TestClass]
14+
public class System_IO_StreamReader_SkipLines
15+
{
16+
[TestMethod]
17+
public void SkipLines()
18+
{
19+
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
20+
"Examples_System_IO_FileInfo_SkipLines.txt");
21+
22+
File.WriteAllLines(filePath, new []
23+
{
24+
"Line1",
25+
"Line2",
26+
"Line3",
27+
"Line4"
28+
});
29+
30+
using (var file = File.OpenText(filePath))
31+
{
32+
file.SkipLines(2);
33+
var nextLine = file.ReadLine();
34+
35+
// Unit Test
36+
Assert.AreEqual("Line3", nextLine);
37+
}
38+
}
39+
}
40+
}

test/Z.IO.Test/Z.IO.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<Compile Include="System.IO.FileInfo\FileInfo.WriteAllBytes.cs" />
101101
<Compile Include="System.IO.FileInfo\FileInfo.WriteAllLines.cs" />
102102
<Compile Include="System.IO.FileInfo\FileInfo.WriteAllText.cs" />
103+
<Compile Include="System.IO.StreamReader\StreamReader.SkipLines.cs" />
103104
<Compile Include="System.IO.Stream\Stream.ReadToEnd.cs" />
104105
<Compile Include="System.IO.Stream\Stream.ToByteArray.cs" />
105106
<Compile Include="System.IO.Stream\Stream.ToMD5Hash.cs" />

0 commit comments

Comments
 (0)