Class ExConsoleChooseFromEnum +
+Provides extension methods for ExConsole to support simple menus based on enum values.
+Inheritance
+Inherited Members
+Namespace: ExtendedConsole
+Assembly: ExtendedConsole.dll
+Syntax
+public static class ExConsoleChooseFromEnum
+ Methods +
+ + + +ChooseFromEnum<T>(ExConsole, MenuDisplayArgs)
+Displays enum members as a menu for the user to choose from.
+Declaration
+public static T ChooseFromEnum<T>(this ExConsole self, MenuDisplayArgs displayArgs)
+ where T : Enum
+ Parameters
+Type | +Name | +Description | +
---|---|---|
ExConsole | +self | +The current instance of ExConsole. + |
+
MenuDisplayArgs | +displayArgs | +An instance of the MenuDisplayArgs class holding the display configuration of the enum based menu. + |
+
Returns
+Type | +Description | +
---|---|
T | +The member of the enum the user selected. + |
+
Type Parameters
+Name | +Description | +
---|---|
T | +The type of the enum. + |
+
Examples
+Display the names of the members of the ConsoleColor enum, +asking the user to choose a color from the list. +the color variable is of type ConsoleColor.
+var color = exConsole.ChooseFromEnum<ConsoleColor>(
+ new MenuDisplayArgs(
+ "Choose a foreground color",
+ "Please choose a color.",
+ false,
+ "Please choose from the above list.")
+);
+
+ Exceptions
+Type | +Condition | +
---|---|
System.ArgumentNullException | +Thrown when |
+
System.ArgumentException | +Thrown when any of the string properties of |
+
System.Xml.XmlException | +Thrown when any of the string properties of |
+
ChooseFromEnum<T>(ExConsole, String, MenuDisplayArgs)
+Displays enum members as a menu for the user to choose from.
+Declaration
+public static T? ChooseFromEnum<T>(this ExConsole self, string quitText, MenuDisplayArgs displayArgs)
+ where T : struct, Enum
+ Parameters
+Type | +Name | +Description | +
---|---|---|
ExConsole | +self | +The current instance of ExConsole. + |
+
System.String | +quitText | +The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + |
+
MenuDisplayArgs | +displayArgs | +An instance of the MenuDisplayArgs class holding the display configuration of the enum based menu. + |
+
Returns
+Type | +Description | +
---|---|
System.Nullable<T> | +The member of the enum the user selected, or null if the user selected the "quit" menu item. + |
+
Type Parameters
+Name | +Description | +
---|---|
T | +The type of the enum. + |
+
Examples
+Display the names of the members of the ConsoleColor enum, +asking the user to choose a color from the list, or "none". +the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none".
+var color = exConsole.ChooseFromEnum<ConsoleColor>(
+ "<c f='red'>none</c>",
+ new MenuDisplayArgs(
+ "Choose a foreground color",
+ "Please choose a color or <c f='red>none</c> to keep current color.",
+ invalidSelectionErrorMessage:"Please choose from the above list.")
+);
+
+ Exceptions
+Type | +Condition | +
---|---|
System.ArgumentNullException | +Thrown when |
+
System.ArgumentException | +Thrown when any of the string properties of |
+
System.Xml.XmlException | +Thrown when any of the string properties of |
+
ChooseFromEnum<T>(ExConsole, String, Boolean)
+Note:
++This method is deprecated and will be removed in future versions. +Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. +
++Displays enum members as a menu for the user to choose from. +
+Declaration
+[Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead.")]
+public static T ChooseFromEnum<T>(this ExConsole self, string title, bool clearWhenSelected)
+ where T : Enum
+ Parameters
+Type | +Name | +Description | +
---|---|---|
ExConsole | +self | +The current instance of ExConsole. + |
+
System.String | +title | +The title of the menu. + |
+
System.Boolean | +clearWhenSelected | +A boolean value to determine +whether the menu should still be displayed after the user have chosen an option. + |
+
Returns
+Type | +Description | +
---|---|
T | +The member of the enum the user selected. + |
+
Type Parameters
+Name | +Description | +
---|---|
T | +The type of the enum. + |
+
Examples
+Display the names of the members of the ConsoleColor enum, +asking the user to choose a color from the list. +the color variable is of type ConsoleColor.
+var color = exConsole.ChooseFromEnum<ConsoleColor>(
+ "Choose a foreground color",
+ true
+);
+
+ Exceptions
+Type | +Condition | +
---|---|
System.ArgumentNullException | +Thrown when |
+
System.ArgumentException | +Thrown when |
+
System.Xml.XmlException | +Thrown when |
+
ChooseFromEnum<T>(ExConsole, String, String, Boolean)
+Note:
++This method is deprecated and will be removed in future versions. +Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. +
++Displays enum members as a menu for the user to choose from. +
+Declaration
+[Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the ChooseFromEnum<T> overload that takes a string and an instance of MenuDisplayArgs as an argument instead.")]
+public static T? ChooseFromEnum<T>(this ExConsole self, string title, string quitText, bool clearWhenSelected)
+ where T : struct, Enum
+ Parameters
+Type | +Name | +Description | +
---|---|---|
ExConsole | +self | +The current instance of ExConsole. + |
+
System.String | +title | +The title of the menu. + |
+
System.String | +quitText | +The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + |
+
System.Boolean | +clearWhenSelected | +A boolean value to determine +whether the menu should still be displayed after the user have chosen an option. + |
+
Returns
+Type | +Description | +
---|---|
System.Nullable<T> | +The member of the enum the user selected. + |
+
Type Parameters
+Name | +Description | +
---|---|
T | +The type of the enum. + |
+
Examples
+Display the names of the members of the ConsoleColor enum, +asking the user to choose a color from the list, or "none". +the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none".
+var color = exConsole.ChooseFromEnum<ConsoleColor>(
+ "Choose a foreground color, or <c f='red>none</c> to keep current color.",
+ "<c f='red'>none</c>",
+ true
+);
+
+ Exceptions
+Type | +Condition | +
---|---|
System.ArgumentNullException | +Thrown when |
+
System.ArgumentException | +Thrown when |
+
System.Xml.XmlException | +Thrown when |
+
ChooseFromEnum<T>(ExConsole, String, String, String, Boolean)
+Note:
++This method is deprecated and will be removed in future versions. +Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. +
++Displays enum members as a menu for the user to choose from. +
+Declaration
+[Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead.")]
+public static T ChooseFromEnum<T>(this ExConsole self, string title, string pleaseSelectText, string invalidSelectionText, bool clearWhenSelected)
+ where T : Enum
+ Parameters
+Type | +Name | +Description | +
---|---|---|
ExConsole | +self | +The current instance of ExConsole. + |
+
System.String | +title | +The title of the menu. + |
+
System.String | +pleaseSelectText | +The text to show below the menu. + |
+
System.String | +invalidSelectionText | +The text to show when the user enters an invalid value. + |
+
System.Boolean | +clearWhenSelected | +A boolean value to determine +whether the menu should still be displayed after the user have chosen an option. + |
+
Returns
+Type | +Description | +
---|---|
T | +The member of the enum the user selected. + |
+
Type Parameters
+Name | +Description | +
---|---|
T | +The type of the enum. + |
+
Examples
+Display the names of the members of the ConsoleColor enum, +asking the user to choose a color from the list. +the color variable is of type ConsoleColor.
+var color = exConsole.ChooseFromEnum<ConsoleColor>(
+ "Choose a foreground color",
+ "Please choose a color.",
+ "Please choose from the above list.",
+ true
+);
+
+ Exceptions
+Type | +Condition | +
---|---|
System.ArgumentNullException | +Thrown when |
+
System.ArgumentException | +Thrown when any of |
+
System.Xml.XmlException | +Thrown when |
+
ChooseFromEnum<T>(ExConsole, String, String, String, String, Boolean)
+Note:
++This method is deprecated and will be removed in future versions. +Use the ChooseFromEnum<T> overload that takes an instance of MenuDisplayArgs as an argument instead. +
++Displays enum members as a menu for the user to choose from. +
+Declaration
+[Obsolete("this method is deprecated and will be removed in future versions.\r\nUse the ChooseFromEnum<T> overload that takes a string and an instance of MenuDisplayArgs as an argument instead.")]
+public static T? ChooseFromEnum<T>(this ExConsole self, string title, string pleaseSelectText, string invalidSelectionText, string quitText, bool clearWhenSelected)
+ where T : struct, Enum
+ Parameters
+Type | +Name | +Description | +
---|---|---|
ExConsole | +self | +The current instance of ExConsole. + |
+
System.String | +title | +The title of the menu. + |
+
System.String | +pleaseSelectText | +The text to show below the menu. + |
+
System.String | +invalidSelectionText | +The text to show when the user enters an invalid value. + |
+
System.String | +quitText | +The title of a menu item that isn't a member of the enum, to enable the user to return without choosing. + |
+
System.Boolean | +clearWhenSelected | +A boolean value to determine +whether the menu should still be displayed after the user have chosen an option. + |
+
Returns
+Type | +Description | +
---|---|
System.Nullable<T> | +The member of the enum the user selected. + |
+
Type Parameters
+Name | +Description | +
---|---|
T | +The type of the enum. + |
+
Examples
+Display the names of the members of the ConsoleColor enum, +asking the user to choose a color from the list, or "none". +the color variable is of type Nullable<ConsoleColor> and will be null if the user choose "none".
+var color = exConsole.ChooseFromEnum<ConsoleColor>(
+ "Choose a foreground color",
+ "Please choose a color or <c f='red>none</c> to keep current color.",
+ "Please choose from the above list.",
+ "<c f='red'>none</c>",
+ true
+);
+
+ Exceptions
+Type | +Condition | +
---|---|
System.ArgumentNullException | +Thrown when |
+
System.ArgumentException | +Thrown when any of |
+
System.Xml.XmlException | +Thrown when |
+