xtd 0.2.0
Loading...
Searching...
No Matches

◆ to_string() [2/3]

template<typename enum_t = std::nullptr_t>
xtd::string xtd::enum_object< enum_t >::to_string ( const xtd::string format) const
inline

Converts the value of this instance to its equivalent string representation using the specified format.

Parameters
formatA format string.
Returns
The string representation of the value of this instance as specified by format.
Exceptions
xtd::format_exceptionformat contains an invalid specification.
Remarks
The format parameter can be one of the following format strings: "G" or "g", "D" or "d", "X" or "x", and "F" or "f" (the format string is not case-sensitive). If format is null or an empty string (""), the general format specifier ("G") is used. For more information about the enumeration format strings and formatting enumeration values, see Enumeration Format Strings. For more information about formatting in general, see Formatting Types.
Notes to caller
If multiple enumeration members have the same underlying value and you attempt to retrieve the string representation of an enumeration member's name based on its underlying value, your code should not make any assumptions about which name the method will return. For example, the following enumeration defines two members, shade::gray and shade::grey, that have the same underlying value.
enum shade {
white = 0, gray = 1, grey = 1, black = 2
};
@ black
The color black.
@ gray
The color gray.
@ white
The color white.
The following method call attempts to retrieve the name of a member of the shade enumeration whose underlying value is 1. The method can return either "gray" or "grey", and your code should not make any assumptions about which string will be returned.
string shade_name = enum_object<shade>(as<shade>(1)).to_string("F");
xtd::string to_string() const noexcept override
Returns a xtd::string that represents the current object.
Definition enum_object.h:135
Provides the base class for enumerations.
Definition enum_object.h:41