-
-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from adamfisher/master
Added StreamReader.SkipLines() extension method.
- Loading branch information
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
test/Z.IO.Test/System.IO.StreamReader/StreamReader.SkipLines.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters