#include <xtd/collections/specialized/string_key_value_pair>
#include <xtd/collections/generic/list>
#include <xtd/boxing>
#include <xtd/console>
#include <xtd/environment>
class setup_serializer :
public object {
public:
setup_serializer() = default;
void add_key_value(const string& key, const object& value) {
key_values_.push_back({key, value.
to_string()});
}
void title(const string& title) {title_ = title;}
for (const auto& [key, value] : key_values_)
return result;
}
private:
pair_collection key_values_;
string title_;
};
struct setup {
int width = 0;
int height = 0;
};
auto main() -> int {
auto my_application_setup = setup {10, 10, 300, 300, "My application", {1, 2, 3}};
auto serializer = setup_serializer {};
serializer.title("My application setup");
serializer.add_key_value(
"x",
boxing(my_application_setup.x));
serializer.add_key_value(
"y",
boxing(my_application_setup.y));
serializer.add_key_value(
"width",
boxing(my_application_setup.width));
serializer.add_key_value(
"height",
boxing(my_application_setup.height));
serializer.add_key_value(
"text",
boxing(my_application_setup.text));
serializer.add_key_value(
"version",
boxing(my_application_setup.version));
}
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:80
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static xtd::string new_line() noexcept
Gets the newline string defined for this environment.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
virtual xtd::string to_string() const noexcept
Returns a xtd::string that represents the current object.
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.hpp:114
auto boxing(const type_t &value) noexcept
Allows to box an object.
Definition boxing.hpp:53
@ y
The Y key.
Definition console_key.hpp:136
@ x
The X key.
Definition console_key.hpp:134
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
The xtd::collections::specialized namespace contains specialized and strongly-typed collections; for ...
Definition string_collection.hpp:13
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
string to_string() const noexcept override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:375