File tree Expand file tree Collapse file tree 5 files changed +98
-0
lines changed Expand file tree Collapse file tree 5 files changed +98
-0
lines changed Original file line number Diff line number Diff line change
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
+ //
8
+
9
+ using System ;
10
+ using System . IO ;
11
+ using System . Linq ;
12
+
13
+ public static partial class Extensions
14
+ {
15
+ /// <summary>Gets the total number of lines in a file. </summary>
16
+ /// <param name="this">The file to perform the count on.</param>
17
+ /// <returns>The total number of lines in a file. </returns>
18
+ public static int CountLines ( this FileInfo @this )
19
+ {
20
+ return File . ReadAllLines ( @this . FullName ) . Length ;
21
+ }
22
+
23
+ /// <summary>Gets the total number of lines in a file that satisfy the condition in the predicate function.</summary>
24
+ /// <param name="this">The file to perform the count on.</param>
25
+ /// <param name="predicate">A function to test each line for a condition.</param>
26
+ /// <returns>The total number of lines in a file that satisfy the condition in the predicate function.</returns>
27
+ public static int CountLines ( this FileInfo @this , Func < string , bool > predicate )
28
+ {
29
+ return File . ReadAllLines ( @this . FullName ) . Count ( predicate ) ;
30
+ }
31
+ }
Original file line number Diff line number Diff line change
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
+
8
+ using System . IO ;
9
+ using System . Linq ;
10
+
11
+ public static partial class Extensions
12
+ {
13
+ /// <summary>
14
+ /// Skips the specified number of lines in a stream reader based on its current position.
15
+ /// </summary>
16
+ /// <param name="this">The stream reader.</param>
17
+ /// <param name="skipCount">The number of lines to skip.</param>
18
+ public static void SkipLines ( this StreamReader @this , int skipCount )
19
+ {
20
+ for ( var i = 0 ; i < skipCount && ! @this . EndOfStream ; i ++ )
21
+ {
22
+ @this . ReadLine ( ) ;
23
+ }
24
+ }
25
+ }
Original file line number Diff line number Diff line change 91
91
<Compile Include =" System.IO.FileInfo\FileInfo.AppendAllLines.cs" />
92
92
<Compile Include =" System.IO.FileInfo\FileInfo.AppendAllText.cs" />
93
93
<Compile Include =" System.IO.FileInfo\FileInfo.ChangeExtension.cs" />
94
+ <Compile Include =" System.IO.FileInfo\FileInfo.CountLines.cs" />
94
95
<Compile Include =" System.IO.FileInfo\FileInfo.CreateDirectory.cs" />
95
96
<Compile Include =" System.IO.FileInfo\FileInfo.EnsureDirectoryExists.cs" />
96
97
<Compile Include =" System.IO.FileInfo\FileInfo.GetDirectoryFullName.cs" />
110
111
<Compile Include =" System.IO.FileInfo\FileInfo.WriteAllBytes.cs" />
111
112
<Compile Include =" System.IO.FileInfo\FileInfo.WriteAllLines.cs" />
112
113
<Compile Include =" System.IO.FileInfo\FileInfo.WriteAllText.cs" />
114
+ <Compile Include =" System.IO.StreamReader\StreamReader.SkipLines.cs" />
113
115
<Compile Include =" System.IO.Stream\Stream.ReadToEnd.cs" />
114
116
<Compile Include =" System.IO.Stream\Stream.ToByteArray.cs" />
115
117
<Compile Include =" System.IO.Stream\Stream.ToMD5Hash.cs" />
Original file line number Diff line number Diff line change
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 , "Examples_System_IO_FileInfo_SkipLines.txt" ) ;
20
+
21
+ File . WriteAllLines ( filePath , new [ ]
22
+ {
23
+ "Line1" ,
24
+ "Line2" ,
25
+ "Line3" ,
26
+ "Line4"
27
+ } ) ;
28
+
29
+ using ( var file = File . OpenText ( filePath ) )
30
+ {
31
+ file . SkipLines ( 2 ) ;
32
+ var nextLine = file . ReadLine ( ) ;
33
+
34
+ // Unit Test
35
+ Assert . AreEqual ( "Line3" , nextLine ) ;
36
+ }
37
+ }
38
+ }
39
+ }
Original file line number Diff line number Diff line change 100
100
<Compile Include =" System.IO.FileInfo\FileInfo.WriteAllBytes.cs" />
101
101
<Compile Include =" System.IO.FileInfo\FileInfo.WriteAllLines.cs" />
102
102
<Compile Include =" System.IO.FileInfo\FileInfo.WriteAllText.cs" />
103
+ <Compile Include =" System.IO.StreamReader\StreamReader.SkipLines.cs" />
103
104
<Compile Include =" System.IO.Stream\Stream.ReadToEnd.cs" />
104
105
<Compile Include =" System.IO.Stream\Stream.ToByteArray.cs" />
105
106
<Compile Include =" System.IO.Stream\Stream.ToMD5Hash.cs" />
You can’t perform that action at this time.
0 commit comments