CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
i_dictionary_of_t_key_t_value_converter.h
1#pragma once
2
3#include <system/type_info.h>
4#include <system/object_ext.h>
5#include <system/func.h>
6#include <system/details/pointer_collection_helpers.h>
7#include <system/constraints.h>
8#include <system/collections/idictionary.h>
9#include <system/collections/dictionary.h>
10#include <system/collections/collection_extensions.h>
11#include <functional>
12#include <cstdint>
13
14#include "system/text/json/json_collection_extensions.h"
15#include "system/text/json/serialization/converters/collection/dictionary_default_converter.h"
16#include "system/text/json/serialization/json_serializer_options.h"
17#include "system/text/json/serialization/read_stack.h"
18#include "system/text/json/serialization/read_stack_frame.h"
19#include "system/text/json/throw_helper.h"
20#include "system/text/json/reader/utf8_json_reader.h"
21
22namespace System {
23
24namespace Text {
25
26namespace Json {
27
28namespace Serialization {
29
30namespace Converters {
31
32template<typename TDictionary, typename TKey, typename TValue>
33class IDictionaryOfTKeyTValueConverter final : public DictionaryDefaultConverter<TDictionary, TKey, TValue>
34{
36 assert_is_base_of(BaseT_IDictionary, TDictionary);
37
40
41 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
42 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
43
44 template<typename FT0, typename FT1, typename FT2> friend class IDictionaryOfTKeyTValueConverter;
45
46public:
47
48 bool get_CanPopulate() override
49 {
50 return true;
51 }
52
54 {
55 ASPOSE_UNUSED(options);
56 // Deserialize as Dictionary<TKey,TValue> for interface types that support it.
57 if (jsonTypeInfo->get_HasCreateObject() == false && JsonConverter<TDictionary>::get_Type().IsAssignableFrom(System::ObjectExt::GetType<Collections::Generic::Dictionary<TKey, TValue>>()))
58 {
59
60 jsonTypeInfo->set_CreateObject(static_cast<Func<System::SharedPtr<Object>>>(static_cast<std::function<System::SharedPtr<System::Object>()>>([]() -> System::SharedPtr<System::Object>
61 {
62 return System::MakeObject<Collections::Generic::Dictionary<TKey, TValue>>();
63 })));
64 }
65 }
66
67 void SetTemplateWeakPtr(uint32_t argument) override
68 {
69 switch (argument)
70 {
71 case 0:
73 break;
74
75 case 1:
77 break;
78
79 case 2:
81 break;
82
83 }
84 }
85
86protected:
87
88 void Add(TKey key, const TValue& value, System::SharedPtr<JsonSerializerOptions> options, ReadStack& state) override
89 {
90 TDictionary collection = System::ExplicitCast<TDictionary>(state.Current.ReturnValue);
91
92 collection->idx_set(key, value);
93
94 if (this->get_IsValueType())
95 {
96 state.Current.ReturnValue = System::ExplicitCast<System::Object>(collection);
97 };
98 }
99
100 void CreateCollection(Utf8JsonReader& reader, ReadStack& state) override
101 {
103 TDictionary returnValue = System::ExplicitCast<TDictionary>(state.Current.ReturnValue);
104 if (returnValue->get_IsReadOnly())
105 {
106 state.Current.ReturnValue.reset();
107 // clear out for more accurate JsonPath reporting.
109 }
110 }
111
112};
113
114} // namespace Converters
115} // namespace Serialization
116} // namespace Json
117} // namespace Text
118} // namespace System
Forward declaration of Dictionary class.
Definition: dictionary.h:96
Interface for dictionary-alike containers. Objects of this class should only be allocated using Syste...
Definition: idictionary.h:21
Function delegate. This type should be allocated on stack and passed to functions by value or by refe...
Definition: func.h:82
static std::enable_if< std::is_fundamental< T >::value &&!std::is_enum< T >::value, constSystem::TypeInfo & >::type GetType()
Implements typeof() translation. Overload for primitive types.
Definition: object_type.h:94
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
System::SharedPtr< Object > ReturnValue
Definition: read_stack_frame.h:59
Definition: read_stack.h:35
ReadStackFrame Current
Definition: read_stack.h:44
void SetTemplateWeakPtr(uint32_t argument) override
Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containe...
Definition: dictionary_default_converter.h:100
Definition: i_dictionary_of_t_key_t_value_converter.h:34
void CreateCollection(Utf8JsonReader &reader, ReadStack &state) override
Definition: i_dictionary_of_t_key_t_value_converter.h:100
bool get_CanPopulate() override
Definition: i_dictionary_of_t_key_t_value_converter.h:48
void ConfigureJsonTypeInfo(System::SharedPtr< Metadata::JsonTypeInfoBase > jsonTypeInfo, System::SharedPtr< JsonSerializerOptions > options) override
Definition: i_dictionary_of_t_key_t_value_converter.h:53
void SetTemplateWeakPtr(uint32_t argument) override
Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containe...
Definition: i_dictionary_of_t_key_t_value_converter.h:67
void Add(TKey key, const TValue &value, System::SharedPtr< JsonSerializerOptions > options, ReadStack &state) override
Definition: i_dictionary_of_t_key_t_value_converter.h:88
Definition: json_converter_of_t.h:80
static void ThrowNotSupportedException_CannotPopulateCollection(const TypeInfo &type, Utf8JsonReader &reader, ReadStack &state)
Definition: utf8_json_reader.h:78
@ Text
Defines color adjustment information for text.
Definition: db_command.h:9
decltype(Ref(std::declval< T & >())) Ref(const std::reference_wrapper< T > &wrapper)
Wrapper to make sure Ref(std::ref(DynamicWeakPtr)) works.
Definition: dynamic_weak_ptr.h:207