CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
i_enumerable_converter.h
1#pragma once
2
3#include <system/type_info.h>
4#include <system/object_ext.h>
5#include <system/details/pointer_collection_helpers.h>
6#include <system/constraints.h>
7#include <system/collections/list.h>
8#include <system/collections/ienumerator_ng.h>
9#include <system/collections/ienumerable_ng.h>
10#include <cstdint>
11
12#include "system/text/json/serialization/converters/collection/json_collection_converter.h"
13#include "system/text/json/serialization/read_stack.h"
14#include "system/text/json/serialization/read_stack_frame.h"
15#include "system/text/json/reader/utf8_json_reader.h"
16#include "system/text/json/serialization/json_serializer_options.h"
17#include "system/text/json/throw_helper.h"
18#include "system/text/json/writer/utf8_json_writer.h"
19#include "system/text/json/serialization/write_stack.h"
20#include "system/text/json/serialization/write_stack_frame.h"
21#include "system/text/json/serialization/json_converter.h"
22
23namespace System {
24
25namespace Text {
26
27namespace Json {
28
29namespace Serialization {
30
31namespace Converters {
32
33template<typename TCollection>
34class IEnumerableConverter final : public JsonCollectionConverter<TCollection, System::SharedPtr<Object>>
35{
37 assert_is_base_of(BaseT_IEnumerable, TCollection);
38
41
42 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
43 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
44
45 template<typename FT0> friend class IEnumerableConverter;
46
47public:
48
50 {
51 return false;
52 }
53
55 : _isDeserializable(System::ObjectExt::GetType<TCollection>().IsAssignableFrom(System::ObjectExt::GetType<Collections::Generic::List<System::SharedPtr<Object>>>()))
56 {
57 }
58
59 void SetTemplateWeakPtr(uint32_t argument) override
60 {
61 switch (argument)
62 {
63 case 0:
65 break;
66
67 }
68 }
69
70protected:
71
72 void Add(const System::SharedPtr<Object>& value, ReadStack& state) override
73 {
74 (System::ExplicitCast<System::Collections::Generic::List<System::SharedPtr<System::Object>>>(state.Current.ReturnValue))->Add(value);
75 }
76
78 {
79 ASPOSE_UNUSED(options);
80 if (!_isDeserializable)
81 {
83 }
84
85 state.Current.ReturnValue = System::MakeObject<Collections::Generic::List<System::SharedPtr<Object>>>();
86 }
87
89 {
91 if (state.Current.CollectionEnumerator == nullptr)
92 {
93 enumerator = System::ExplicitCast<Collections::IEnumerable>(value)->GetEnumerator();
94 state.Current.CollectionEnumerator = enumerator;
95 if (!enumerator->MoveNext())
96 {
97 return true;
98 }
99 }
100 else
101 {
102 enumerator = System::ExplicitCast<Collections::IEnumerator>(state.Current.CollectionEnumerator);
103 }
104
106 do
107 {
108 if (this->ShouldFlush(System::Ref(state), writer))
109 {
110 return false;
111 }
112
113 System::SharedPtr<Object> element = enumerator->get_Current();
114 if (!converter->TryWrite(writer, element, options, System::Ref(state)))
115 {
116 return false;
117 }
118
120 } while (enumerator->MoveNext());
121
122 return true;
123 }
124
125private:
126
127 bool _isDeserializable;
128
129};
130
131} // namespace Converters
132} // namespace Serialization
133} // namespace Json
134} // namespace Text
135} // namespace System
IEnumerable is the base interface for all non-generic collections that can be enumerated.
Definition: ienumerable_ng.h:10
Provides static methods that emulate C# Object methods called for non-Object C++ types (strings,...
Definition: object_ext.h:23
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:51
virtual const TypeInfo & GetType() const
Gets actual type of object. Analog of C# System.Object.GetType() call.
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: i_enumerable_converter.h:59
bool OnWriteResume(System::SharedPtr< Utf8JsonWriter > writer, TCollection value, System::SharedPtr< JsonSerializerOptions > options, WriteStack &state) override
Definition: i_enumerable_converter.h:88
bool get_SupportsCreateObjectDelegate() override
Definition: i_enumerable_converter.h:49
void Add(const System::SharedPtr< Object > &value, ReadStack &state) override
Definition: i_enumerable_converter.h:72
IEnumerableConverter()
Definition: i_enumerable_converter.h:54
void CreateCollection(Utf8JsonReader &reader, ReadStack &state, System::SharedPtr< JsonSerializerOptions > options) override
Definition: i_enumerable_converter.h:77
Definition: json_collection_converter.h:43
static System::SharedPtr< JsonConverter< System::SharedPtr< Object > > > GetElementConverter(System::SharedPtr< Metadata::JsonTypeInfoBase > elementTypeInfo)
Definition: json_collection_converter.h:358
void SetTemplateWeakPtr(uint32_t argument) override
Definition: json_collection_converter.h:316
static bool ShouldFlush(WriteStack &state, System::SharedPtr< Utf8JsonWriter > writer)
Definition: json_converter_of_t.h:80
static void ThrowNotSupportedException_CannotPopulateCollection(const TypeInfo &type, Utf8JsonReader &reader, ReadStack &state)
Definition: utf8_json_reader.h:78
System::SharedPtr< Object > CollectionEnumerator
Definition: write_stack_frame.h:53
Definition: write_stack.h:34
WriteStackFrame Current
Definition: write_stack.h:45
@ 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