xtd 0.2.0
Loading...
Searching...
No Matches
parse_enum_class.cpp

Shows how to use format xtd::parse<num class> method with enum class values.

#include <xtd/console>
#include <xtd/enum_class>
#include <xtd/parse>
using namespace xtd;
enum_class_(, week_day,
);
auto main() -> int {
auto wd1 = parse<week_day>("wednesday");
auto wd2 = enum_object<>::parse<week_day>("WEDNESDAY", true);
auto wd3 = parse<week_day>("2");
try {
auto wd4 = parse<week_day>("january");
} catch (const system_exception& e) {
console::write_line("Exception : {}", e.message());
}
}
// This code produces the following output :
//
// wednesday
// wednesday
// wednesday
// Exception : invalid character found
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
The exception that is thrown when a method call is invalid for the object's current state.
Definition system_exception.hpp:18
#define enum_class_(namespace_name, enum_class_t,...)
Provides the registration struct for enum class.
Definition enum_class.hpp:52
value_t parse(const std::string &str)
Convert a string into a type.
Definition parse.hpp:34
@ e
The E key.
Definition console_key.hpp:96
@ tuesday
Indicates tuesday.
Definition day_of_week.hpp:31
@ saturday
Indicates saturday.
Definition day_of_week.hpp:39
@ sunday
Indicates sunday.
Definition day_of_week.hpp:27
@ monday
Indicates monday.
Definition day_of_week.hpp:29
@ wednesday
Indicates wednesday.
Definition day_of_week.hpp:33
@ thursday
Indicates thursday.
Definition day_of_week.hpp:35
@ friday
Indicates friday.
Definition day_of_week.hpp:37
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
static enum_type parse(const xtd::string &str)
Converts the string to its enum_type equivalent.
Definition enum_object.hpp:228