11using TJC . StringExtensions . Lines ;
22using TJC . StringExtensions . Padding ;
33
4- namespace TJC . StringExtensions . Header
4+ namespace TJC . StringExtensions . Header ;
5+
6+ /// <summary>
7+ /// Extensions for creating text headers.
8+ /// </summary>
9+ public static class HeaderExtensions
510{
6- public static class HeaderExtensions
11+ /// <summary>
12+ /// Create a text header with a border of specified characters.
13+ /// <para></para>
14+ /// For use within console applications.
15+ /// </summary>
16+ /// <param name="lines"></param>
17+ /// <param name="internalLineLimit"></param>
18+ /// <param name="character"></param>
19+ /// <param name="linePrefix"></param>
20+ /// <param name="lineSuffix"></param>
21+ /// <returns></returns>
22+ public static IEnumerable < string > GenerateHeader ( this IEnumerable < string > lines , int internalLineLimit = 70 , char character = '#' , string linePrefix = "### " , string lineSuffix = " ###" )
723 {
8- public static IEnumerable < string > GenerateHeader ( this IEnumerable < string > lines , int internalLineLimit = 70 , char character = '#' , string linePrefix = "### " , string lineSuffix = " ###" )
9- {
10- var tempLines = new List < string > ( ) ;
11- // Get lines
12- foreach ( var newLine in lines )
13- foreach ( var splitLine in newLine . SplitNewLine ( ) )
14- foreach ( var line in splitLine . SplitLines ( internalLineLimit ) )
15- tempLines . Add ( line ) ;
24+ var tempLines = new List < string > ( ) ;
25+ // Get lines
26+ foreach ( var newLine in lines )
27+ foreach ( var splitLine in newLine . SplitNewLine ( ) )
28+ foreach ( var line in splitLine . SplitLines ( internalLineLimit ) )
29+ tempLines . Add ( line ) ;
1630
17- // Get border
18- var longestLine = tempLines . Max ( x => x . Length ) ;
19- var headerBorder = new string ( character , longestLine + linePrefix . Length + lineSuffix . Length ) ;
31+ // Get border
32+ var longestLine = tempLines . Max ( x => x . Length ) ;
33+ var headerBorder = new string ( character , longestLine + linePrefix . Length + lineSuffix . Length ) ;
2034
21- // Get lines with prefix and suffix
22- var headerLines = new List < string > { headerBorder } ;
23- foreach ( var line in tempLines )
24- headerLines . Add ( $ "{ linePrefix } { line . PadBoth ( longestLine ) } { lineSuffix } ") ;
25- headerLines . Add ( headerBorder ) ;
26- return headerLines ;
27- }
35+ // Get lines with prefix and suffix
36+ var headerLines = new List < string > { headerBorder } ;
37+ foreach ( var line in tempLines )
38+ headerLines . Add ( $ "{ linePrefix } { line . PadBoth ( longestLine ) } { lineSuffix } ") ;
39+ headerLines . Add ( headerBorder ) ;
40+ return headerLines ;
2841 }
2942}
0 commit comments