3#include <system/type_info.h>
4#include <system/span.h>
5#include <system/object_ext.h>
6#include <system/nullable.h>
7#include <system/func.h>
8#include <system/diagnostics/debug.h>
9#include <system/details/pointer_collection_helpers.h>
10#include <system/details/patterns.h>
11#include <system/details/lambda_capture_holder.h>
12#include <system/delegate.h>
13#include <system/default.h>
14#include <system/array.h>
15#include <system/action.h>
20#include "system/text/json/serialization/json_converter.h"
21#include "system/text/json/serialization/converters/casting_converter.h"
22#include "system/text/json/serialization/json_serializer_options.h"
23#include "system/text/json/serialization/metadata/json_parameter_info_values.h"
24#include "system/text/json/serialization/metadata/json_property_info.h"
25#include "system/text/json/serialization/metadata/json_parameter_info.h"
26#include "system/text/json/serialization/metadata/json_parameter_info_of_t.h"
27#include "system/text/json/serialization/write_stack.h"
28#include "system/text/json/writer/utf8_json_writer.h"
29#include "system/text/json/serialization/converter_strategy.h"
30#include "system/text/json/throw_helper.h"
31#include "system/text/json/serialization/write_stack_frame.h"
32#include "system/text/json/serialization/stack_frame_property_state.h"
33#include "system/text/json/serialization/read_stack.h"
34#include "system/text/json/reader/utf8_json_reader.h"
35#include "system/text/json/json_token_type.h"
36#include "system/text/json/serialization/read_stack_frame.h"
37#include "system/text/json/serialization/json_ignore_condition.h"
47template <
typename>
class JsonConverter;
50template <
typename>
class JsonParameterInfo;
73 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
74 RTTI_INFO_TEMPLATE_CLASS(
ThisType, ThisTypeBaseTypesInfo);
104 return _shouldSerializeTyped;
109 _fastShouldSerialize =
nullptr;
110 SetShouldSerialize(
value);
115 return System::ExplicitCast<System::Object>(System::Default<T>());
120 return System::IsNull(System::Default<T>());
126 return _typedEffectiveConverter;
145 return _fastShouldSerialize;
164 _fastShouldSerialize =
value;
165 _shouldSerializeTyped =
nullptr;
178 _isSetNullable = parameterInfoValues->get_IsNullable();
189 return System::ExplicitCast<System::Object>(_fastGet !=
nullptr ? _fastGet(obj) :
get_Get()(obj));
196 T
value = _fastGet !=
nullptr ? _fastGet(obj) :
get_Get()(obj);
201 if (IsDefaultValue(
value))
213 if (System::IsNull(
value))
216 if (effectiveConverter->get_HandleNullOnWrite())
224 int32_t originalDepth = writer->get_CurrentDepth();
225 effectiveConverter->Write(writer,
value, options);
226 if (originalDepth != writer->get_CurrentDepth())
246 return effectiveConverter->TryWrite(writer,
value, options,
System::Ref(state));
255 T
value = _fastGet !=
nullptr ? _fastGet(obj) :
get_Get()(obj);
264 if (System::IsNull(
value))
270 success = effectiveConverter->TryWriteDataExtensionProperty(writer,
value, options,
System::Ref(state));
282 const auto& setter =
get_Set();
283 auto setValue = [&](
const T&
value) {
if (_fastSet !=
nullptr) _fastSet(obj,
value);
else setter(obj,
value); };
287 if (isNullToken && !effectiveConverter->get_HandleNullOnRead() && !state.
get_IsContinuation())
291 if (System::IsNull(System::Default<T>()))
302 T
value = System::Default<T>();
309 else if (effectiveConverter->get_CanUseDirectReadOrWrite() && state.
Current.
NumberHandling ==
nullptr)
316 T fastValue = effectiveConverter->Read(
System::Ref(reader), propertyType, options);
331 T
value;
bool populatedValue;
335 if (System::ObjectExt::GetType<T>().get_IsValueType() || !populatedValue)
362 if (isNullToken && !effectiveConverter->get_HandleNullOnRead() && !state.
get_IsContinuation())
364 if (!System::IsNull(System::Default<T>()))
369 value = System::ExplicitCast<System::Object>(System::Default<T>());
379 value = System::ExplicitCast<System::Object>(effectiveConverter->Read(
System::Ref(reader), propertyType, options));
385 success = effectiveConverter->TryRead(
System::Ref(reader), propertyType, options,
System::Ref(state), typedValue, System::Discard<bool>());
386 value = System::ExplicitCast<System::Object>(typedValue);
398 System::Details::CollectionHelpers::SetWeakPointer(0, _typedGet);
399 System::Details::CollectionHelpers::SetWeakPointer(2, _typedSet);
400 System::Details::CollectionHelpers::SetWeakPointer(2, _shouldSerializeTyped);
401 System::Details::CollectionHelpers::SetWeakPointer(0, _typedEffectiveConverter);
413 #ifdef ASPOSE_GET_SHARED_MEMBERS
414 void GetSharedMembers(System::Object::shared_members_type& result)
const override
416 JsonPropertyInfoBase::GetSharedMembers(result);
418 result.Add(
"System::Text::Json::Serialization::Metadata::JsonPropertyInfoBase::_typedGet", this->_typedGet);
419 result.Add(
"System::Text::Json::Serialization::Metadata::JsonPropertyInfoBase::_typedSet", this->_typedSet);
420 result.Add(
"System::Text::Json::Serialization::Metadata::JsonPropertyInfoBase::_shouldSerializeTyped", this->_shouldSerializeTyped);
421 result.Add(
"System::Text::Json::Serialization::Metadata::JsonPropertyInfoBase::_typedEffectiveConverter", this->_typedEffectiveConverter);
435 template <
class TEnable = T,
typename std::enable_if<!std::is_same<TEnable, System::SharedPtr<System::Object>>::value,
int>::type = 0>
438 System::Details::LambdaCaptureHolder<Func<System::SharedPtr<Object>, T>> _lch_getter = getter;
440 if (System::IsNull(_getter))
443 _untypedGet =
nullptr;
449 return System::ExplicitCast<System::Object>(_getter(obj));
457 if (_getter ==
nullptr)
460 _untypedGet =
nullptr;
465 return System::ExplicitCast<T>(_getter(obj));
466 })).template AddHeldVariable<Func<System::SharedPtr<Object>,
T>>(
"_getter", _getter);
467 _untypedGet = _getter;
474 if (_setter ==
nullptr)
477 _untypedSet =
nullptr;
482 _setter(obj, System::ExplicitCast<System::Object>(value));
483 })).template AddHeldVariable<Action<System::SharedPtr<Object>,
T>>(
"_setter", _setter);
484 _untypedSet = _setter;
487 template <
class TEnable = T,
typename std::enable_if<!std::is_same<TEnable, System::SharedPtr<System::Object>>::value,
int>::type = 0>
490 System::Details::LambdaCaptureHolder<Action<System::SharedPtr<Object>,
T>> _lch_setter = setter;
491 Action<System::SharedPtr<Object>,
T> &_setter = _lch_setter.GetCapture();
492 if (System::IsNull(_setter))
495 _untypedSet =
nullptr;
501 _setter(obj, System::ExplicitCast<T>(value));
505 template <
class TEnable = T,
typename std::enable_if<!std::is_same<TEnable, System::SharedPtr<System::Object>>::value,
int>::type = 0>
508 System::Details::LambdaCaptureHolder<Func<System::SharedPtr<Object>,
T,
bool>> _lch_predicate = predicate;
509 Func<System::SharedPtr<Object>,
T,
bool> &_predicate = _lch_predicate.GetCapture();
510 if (System::IsNull(_predicate))
512 _shouldSerializeTyped =
nullptr;
513 _shouldSerialize =
nullptr;
516 _shouldSerializeTyped = _predicate;
519 return _predicate(obj, System::ExplicitCast<T>(value));
520 })).template AddHeldVariable<Func<System::SharedPtr<Object>,
System::SharedPtr<Object>,
bool>>(
"_predicate", _predicate);
525 if (predicate ==
nullptr)
527 _shouldSerializeTyped =
nullptr;
528 _shouldSerialize =
nullptr;
531 System::Details::LambdaCaptureHolder<Func<System::SharedPtr<Object>,
System::SharedPtr<Object>,
bool>> _lch_untypedPredicate = predicate;
535 return untypedPredicate(obj, System::ExplicitCast<System::Object>(value));
536 })).template AddHeldVariable<Func<System::SharedPtr<Object>,
T,
bool>>(
"untypedPredicate", untypedPredicate);
537 _shouldSerialize = untypedPredicate;
546 _effectiveConverter = converter;
547 _typedEffectiveConverter = converter;
562 return !IsDefaultValue(value);
568 SetShouldSerialize(
static_cast<Func<System::SharedPtr<Object>,
T,
bool>>(
nullptr));
569 _fastShouldSerialize = predicate;
572 void ConfigureIgnoreCondition(Nullable<JsonIgnoreCondition> ignoreCondition)
override
574 if (ignoreCondition ==
nullptr)
579 SetBuiltInShouldSerialize(&ShouldSerializeIgnoreConditionNever);
583 SetBuiltInShouldSerialize(&ShouldSerializeIgnoreConditionAlways);
589 SetBuiltInShouldSerialize(&ShouldSerializeIgnoreWhenWritingDefault);
590 set_IgnoreDefaultValuesOnWrite(
true);
599 SetBuiltInShouldSerialize(&ShouldSerializeIgnoreWhenWritingDefault);
600 set_IgnoreDefaultValuesOnWrite(
true);
604 SetBuiltInShouldSerialize(&ShouldSerializeIgnoreConditionAlways);
612 CODEPORTING_DEBUG_FAIL1(
System::String::Format(u
"Unknown value of JsonIgnoreCondition '{0}'", ignoreCondition));
616 static bool IsDefaultValue(T value)
618 return System::IsNull(System::Default<T>()) ? System::IsNull(value) :
Default<
T>() ==
value;
Function delegate. This type should be allocated on stack and passed to functions by value or by refe...
Definition: func.h:82
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.
Forward to use within Span class.
Definition: span.h:415
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
static String Format(const SharedPtr< IFormatProvider > &fp, const String &format, const Args &... args)
Formats string in C# style.
Definition: string.h:1449
Nullable< Serialization::JsonNumberHandling > NumberHandling
Definition: read_stack_frame.h:73
void MarkPropertyAsRead(System::Text::Json::Serialization::Metadata::JsonPropertyInfoBase *propertyInfo)
System::SharedPtr< Object > ReturnValue
Definition: read_stack_frame.h:59
Definition: read_stack.h:35
bool get_IsContinuation()
ReadStackFrame Current
Definition: read_stack.h:44
Definition: json_parameter_info_of_t.h:43
Definition: json_property_info.h:80
bool get_CanDeserialize()
const System::SharedPtr< JsonSerializerOptions > & get_Options()
void set_AssociatedParameter(System::SharedPtr< JsonParameterInfoBase > value)
bool get_IgnoreDefaultValuesOnWrite()
const TypeInfo & get_PropertyType()
const TypeInfo & get_DeclaringType()
System::SharedPtr< JsonConverterBase > get_CustomConverter()
void set_HasFastGetter(bool value)
System::SharedPtr< Array< uint8_t > > get_EscapedNameSection()
bool get_IgnoreNullTokensOnRead()
void set_HasFastSetter(bool value)
Definition: json_property_info_of_t.h:69
SetterFn get_FastSetter() const
Definition: json_property_info_of_t.h:138
void set_SetFast(SetterFn value)
Definition: json_property_info_of_t.h:155
bool ReadJsonAndSetMember(System::SharedPtr< Object > obj, ReadStack &state, Utf8JsonReader &reader) override
Definition: json_property_info_of_t.h:276
bool(*)(System::SharedPtr< Object >, T) ShouldSerializeFn
Definition: json_property_info_of_t.h:131
System::SharedPtr< Object > get_DefaultValue() override
Definition: json_property_info_of_t.h:113
void set_Get(Func< System::SharedPtr< Object >, T > value)
Definition: json_property_info_of_t.h:83
void set_ShouldSerializeFast(ShouldSerializeFn value)
Definition: json_property_info_of_t.h:162
void SetTemplateWeakPtr(uint32_t argument) override
Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containe...
Definition: json_property_info_of_t.h:393
void AddJsonParameterInfo(System::SharedPtr< JsonParameterInfoValues > parameterInfoValues) override
Definition: json_property_info_of_t.h:173
const System::SharedPtr< JsonConverter< T > > & get_EffectiveConverter()
Definition: json_property_info_of_t.h:123
bool GetMemberAndWriteJson(System::SharedPtr< Object > obj, WriteStack &state, System::SharedPtr< Utf8JsonWriter > writer) override
Definition: json_property_info_of_t.h:192
void set_ShouldSerialize(Func< System::SharedPtr< Object >, T, bool > value)
Definition: json_property_info_of_t.h:107
const Action< System::SharedPtr< Object >, T > & get_Set()
Definition: json_property_info_of_t.h:90
System::SharedPtr< Object > GetValueAsObject(System::SharedPtr< Object > obj) override
Definition: json_property_info_of_t.h:182
GetterFn get_FastGetter() const
Definition: json_property_info_of_t.h:133
void(*)(System::SharedPtr< Object >, T) SetterFn
Definition: json_property_info_of_t.h:130
T(*)(System::SharedPtr< Object >) GetterFn
Definition: json_property_info_of_t.h:129
void set_Set(Action< System::SharedPtr< Object >, T > value)
Definition: json_property_info_of_t.h:95
JsonPropertyInfo(const TypeInfo &declaringType, System::SharedPtr< System::Text::Json::Serialization::Metadata::JsonTypeInfoBase > declaringTypeInfo, System::SharedPtr< JsonSerializerOptions > options)
Definition: json_property_info_of_t.h:168
ShouldSerializeFn get_FastShouldSerialize() const
Definition: json_property_info_of_t.h:143
const Func< System::SharedPtr< Object >, T, bool > & get_ShouldSerialize()
Definition: json_property_info_of_t.h:102
bool GetMemberAndWriteJsonExtensionData(System::SharedPtr< Object > obj, WriteStack &state, System::SharedPtr< Utf8JsonWriter > writer) override
Definition: json_property_info_of_t.h:250
virtual ~JsonPropertyInfo()
Definition: json_property_info_of_t.h:409
void set_GetFast(GetterFn value)
Definition: json_property_info_of_t.h:148
bool get_PropertyTypeCanBeNull() override
Definition: json_property_info_of_t.h:118
const Func< System::SharedPtr< Object >, T > & get_Get()
Definition: json_property_info_of_t.h:78
bool ReadJsonAsObject(ReadStack &state, Utf8JsonReader &reader, System::SharedPtr< Object > &value) override
Definition: json_property_info_of_t.h:355
Definition: json_type_info_of_t.h:84
static void ThrowInvalidOperationException_DeserializeUnableToAssignNull(const TypeInfo &declaredType)
static void ThrowJsonException_DeserializeUnableToConvertValue(const TypeInfo &propertyType)
static void ThrowInvalidOperationException_IgnoreConditionOnValueTypeInvalid(String clrPropertyName, const TypeInfo &propertyDeclaringType)
static void ThrowJsonException_SerializationConverterWrite(System::SharedPtr< Serialization::JsonConverterBase > converter)
Definition: utf8_json_reader.h:78
JsonTokenType get_TokenType()
StackFramePropertyState PropertyState
Definition: write_stack_frame.h:60
Definition: write_stack.h:34
WriteStackFrame Current
Definition: write_stack.h:45
Represents a particular type and provides information about it.
Definition: type_info.h:109
@ Text
Defines color adjustment information for text.
Definition: db_command.h:9
MulticastDelegate< void(Args...)> Action
Delegate type that references methods that have no return value.
Definition: action.h:40
SmartPtr< X > MakeSharedPtr(X *p)
Converts raw pointer to smart pointer.
Definition: smart_ptr.h:1640
std::enable_if<!IsSmartPtr< T >::value, SmartPtr< T > >::type MakeObject(Args &&... args)
Creates object on heap and returns shared pointer to it.
Definition: smart_ptr.h:1496
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
static auto SafeInvoke(T0 &&expr, T1 &&func)
Implementation of '?.' operator translation.
Definition: object_ext.h:1434
std::enable_if_t< Details::CastType< Source, Result >::None, Result > ExplicitCast(const Source &value)
Casts the source type to the result type using explicit cast. Used when the source and the result typ...
Definition: object_ext.h:960
std::enable_if< IsExceptionWrapper< T >::value, constT & >::type Default()
Returns the reference to the single default-constructed instance of the exception type.
Definition: default.h:16