@@ -8,16 +8,8 @@ namespace Examples
88 /// <summary>
99 /// Provides an eval/print loop for command line argument strings.
1010 /// </summary>
11- internal class Program
11+ internal static class Program
1212 {
13- #region Private Properties
14-
15- /// <summary>
16- /// Gets or sets a value indicating whether show the help.
17- /// </summary>
18- [ Argument ( 'h' , "help" , "Gets or sets a value indicating whether show the help." ) ]
19- private static bool Help { get ; set ; }
20-
2113 /// <summary>
2214 /// Gets or sets a value indicating whether the Bool argument was supplied.
2315 /// </summary>
@@ -30,6 +22,12 @@ internal class Program
3022 [ Argument ( 'f' , "float" , "Gets or sets the value of the Double argument." ) ]
3123 private static double Double { get ; set ; }
3224
25+ /// <summary>
26+ /// Gets or sets a value indicating whether show the help.
27+ /// </summary>
28+ [ Argument ( 'h' , "help" , "Gets or sets a value indicating whether show the help." ) ]
29+ private static bool Help { get ; set ; }
30+
3331 /// <summary>
3432 /// Gets or sets the value of the Int argument.
3533 /// </summary>
@@ -54,9 +52,16 @@ internal class Program
5452 [ Argument ( 's' , "string" ) ]
5553 private static string String { get ; set ; }
5654
57- #endregion Private Properties
58-
59- #region Private Methods
55+ /// <summary>
56+ /// Returns a "pretty" string representation of the provided Type; specifically, corrects the naming of generic Types
57+ /// and appends the type parameters for the type to the name as it appears in the code editor.
58+ /// </summary>
59+ /// <param name="type">The type for which the colloquial name should be created.</param>
60+ /// <returns>A "pretty" string representation of the provided Type.</returns>
61+ public static string ToColloquialString ( this Type type )
62+ {
63+ return ( ! type . IsGenericType ? type . Name : type . Name . Split ( '`' ) [ 0 ] + "<" + String . Join ( ", " , type . GetGenericArguments ( ) . Select ( a => a . ToColloquialString ( ) ) ) + ">" ) ;
64+ }
6065
6166 /// <summary>
6267 /// Application entry point
@@ -152,22 +157,22 @@ private static void Reset()
152157 }
153158
154159 /// <summary>
155- /// Show help for arguments.
160+ /// Show help for arguments.
156161 /// </summary>
157162 private static void ShowHelp ( )
158163 {
159164 var helpAttributes = Arguments . GetArgumentInfo ( typeof ( Program ) ) ;
160165
161- Console . WriteLine ( "Short\t Long\t Function" ) ;
162- Console . WriteLine ( "-----\t ----\t --------" ) ;
166+ var maxLen = helpAttributes . Select ( a => a . Property . PropertyType . ToColloquialString ( ) ) . OrderByDescending ( s => s . Length ) . FirstOrDefault ( ) . Length ;
167+
168+ Console . WriteLine ( $ "Short\t Long\t { "Type" . PadRight ( maxLen ) } \t Function") ;
169+ Console . WriteLine ( $ "-----\t ----\t { "----" . PadRight ( maxLen ) } \t --------") ;
163170
164171 foreach ( var item in helpAttributes )
165172 {
166- var result = item . ShortName + "\t " + item . LongName + "\t " + item . HelpText ;
173+ var result = item . ShortName + "\t " + item . LongName + "\t " + item . Property . PropertyType . ToColloquialString ( ) . PadRight ( maxLen ) + " \t " + item . HelpText ;
167174 Console . WriteLine ( result ) ;
168175 }
169176 }
170-
171- #endregion Private Methods
172177 }
173178}
0 commit comments