Skip to content

Commit

Permalink
Merge pull request #21 from adamfisher/master
Browse files Browse the repository at this point in the history
Added StreamReader.SkipLines() extension method.
  • Loading branch information
JonathanMagnan authored Jan 12, 2019
2 parents b94c79e + 7573954 commit 4dbfd8f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Z.IO/System.IO.StreamReader/StreamReader.SkipLines.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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
// Website & Documentation: https://github.com/zzzprojects/Z.ExtensionMethods
// Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues
// License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
using System.IO;

public static partial class Extensions
{
/// <summary>
/// Skips the specified number of lines in a stream reader based on its current position.
/// </summary>
/// <param name="this">The stream reader.</param>
/// <param name="skipCount">The number of lines to skip.</param>
public static void SkipLines(this StreamReader @this, int skipCount)
{
for (var i = 0; i < skipCount && !@this.EndOfStream; i++)
{
@this.ReadLine();
}
}
}
1 change: 1 addition & 0 deletions src/Z.IO/Z.IO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<Compile Include="System.IO.FileInfo\FileInfo.WriteAllBytes.cs" />
<Compile Include="System.IO.FileInfo\FileInfo.WriteAllLines.cs" />
<Compile Include="System.IO.FileInfo\FileInfo.WriteAllText.cs" />
<Compile Include="System.IO.StreamReader\StreamReader.SkipLines.cs" />
<Compile Include="System.IO.Stream\Stream.ReadToEnd.cs" />
<Compile Include="System.IO.Stream\Stream.ToByteArray.cs" />
<Compile Include="System.IO.Stream\Stream.ToMD5Hash.cs" />
Expand Down
40 changes: 40 additions & 0 deletions test/Z.IO.Test/System.IO.StreamReader/StreamReader.SkipLines.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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
// Website & Documentation: https://github.com/zzzprojects/Z.ExtensionMethods
// Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues
// License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Z.IO.Test
{
[TestClass]
public class System_IO_StreamReader_SkipLines
{
[TestMethod]
public void SkipLines()
{
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
"Examples_System_IO_FileInfo_SkipLines.txt");

File.WriteAllLines(filePath, new []
{
"Line1",
"Line2",
"Line3",
"Line4"
});

using (var file = File.OpenText(filePath))
{
file.SkipLines(2);
var nextLine = file.ReadLine();

// Unit Test
Assert.AreEqual("Line3", nextLine);
}
}
}
}
1 change: 1 addition & 0 deletions test/Z.IO.Test/Z.IO.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<Compile Include="System.IO.FileInfo\FileInfo.WriteAllBytes.cs" />
<Compile Include="System.IO.FileInfo\FileInfo.WriteAllLines.cs" />
<Compile Include="System.IO.FileInfo\FileInfo.WriteAllText.cs" />
<Compile Include="System.IO.StreamReader\StreamReader.SkipLines.cs" />
<Compile Include="System.IO.Stream\Stream.ReadToEnd.cs" />
<Compile Include="System.IO.Stream\Stream.ToByteArray.cs" />
<Compile Include="System.IO.Stream\Stream.ToMD5Hash.cs" />
Expand Down

0 comments on commit 4dbfd8f

Please sign in to comment.