File tree Expand file tree Collapse file tree 1 file changed +37
-2
lines changed
Expand file tree Collapse file tree 1 file changed +37
-2
lines changed Original file line number Diff line number Diff line change 33// Created by: DavidFDev
44
55using System ;
6+ using System . Reflection ;
67
78namespace DavidFDev . DevConsole
89{
@@ -11,6 +12,12 @@ namespace DavidFDev.DevConsole
1112 /// </summary>
1213 public sealed class Parameter
1314 {
15+ #region Constants
16+
17+ private const int MaxEnumNames = 6 ;
18+
19+ #endregion
20+
1421 #region Static methods
1522
1623 /// <summary>
@@ -64,8 +71,7 @@ private Parameter() { }
6471 /// <returns></returns>
6572 internal Parameter SetType < T > ( )
6673 {
67- Type = typeof ( T ) ;
68- return this ;
74+ return SetType ( typeof ( T ) ) ;
6975 }
7076
7177 /// <summary>
@@ -76,6 +82,35 @@ internal Parameter SetType<T>()
7682 internal Parameter SetType ( Type type )
7783 {
7884 Type = type ;
85+
86+ // If the type is an enum, add special help text
87+ if ( type . IsEnum )
88+ {
89+ string enumHelpText = string . Empty ;
90+ if ( type . GetEnumNames ( ) . Length > MaxEnumNames )
91+ {
92+ // Recommend using the help_enum command
93+ enumHelpText = $ "use <b>help_enum { type . Name } </b> to see options";
94+ }
95+ else
96+ {
97+ // Add names to the help text
98+ FieldInfo [ ] values = type . GetFields ( ) ;
99+ bool first = true ;
100+ for ( int i = 0 ; i < values . Length ; i ++ )
101+ {
102+ if ( values [ i ] . Name . Equals ( "value__" ) )
103+ {
104+ continue ;
105+ }
106+
107+ enumHelpText += $ "{ ( first ? "" : ", " ) } { values [ i ] . Name } ={ values [ i ] . GetRawConstantValue ( ) } ";
108+ first = false ;
109+ }
110+ }
111+ HelpText += $ "{ ( HelpText . Length == 0 ? "" : " " ) } ({ enumHelpText } )";
112+ }
113+
79114 return this ;
80115 }
81116
You can’t perform that action at this time.
0 commit comments