// If this method is changed, also change ApplyValueToEnumerable. internal static void ApplyObjectToEnumerable(object value, JsonSerializerOptions options, ref ReadStackFrame frame, bool setPropertyDirectly = false) { if (frame.IsEnumerable()) { if (frame.TempEnumerableValues != null) { frame.TempEnumerableValues.Add(value); } else { ((IList)frame.ReturnValue).Add(value); } } else if (!setPropertyDirectly && frame.IsPropertyEnumerable()) { Debug.Assert(frame.JsonPropertyInfo != null); Debug.Assert(frame.ReturnValue != null); if (frame.TempEnumerableValues != null) { frame.TempEnumerableValues.Add(value); } else { ((IList)frame.JsonPropertyInfo.GetValueAsObject(frame.ReturnValue, options)).Add(value); } } else { Debug.Assert(frame.JsonPropertyInfo != null); frame.JsonPropertyInfo.SetValueAsObject(frame.ReturnValue, value, options); } }
// If this method is changed, also change ApplyObjectToEnumerable. internal static void ApplyValueToEnumerable <TProperty>(ref TProperty value, JsonSerializerOptions options, ref ReadStackFrame frame) { if (frame.IsEnumerable()) { if (frame.TempEnumerableValues != null) { ((IList <TProperty>)frame.TempEnumerableValues).Add(value); } else { ((IList <TProperty>)frame.ReturnValue).Add(value); } } else if (frame.IsPropertyEnumerable()) { Debug.Assert(frame.JsonPropertyInfo != null); Debug.Assert(frame.ReturnValue != null); if (frame.TempEnumerableValues != null) { ((IList <TProperty>)frame.TempEnumerableValues).Add(value); } else { ((IList <TProperty>)frame.JsonPropertyInfo.GetValueAsObject(frame.ReturnValue, options)).Add(value); } } else { Debug.Assert(frame.JsonPropertyInfo != null); frame.JsonPropertyInfo.SetValueAsObject(frame.ReturnValue, value, options); } }
// If this method is changed, also change ApplyObjectToEnumerable. internal static void ApplyValueToEnumerable <TProperty>( ref TProperty value, JsonSerializerOptions options, ref ReadStackFrame frame) { if (frame.IsEnumerable()) { if (frame.TempEnumerableValues != null) { ((IList <TProperty>)frame.TempEnumerableValues).Add(value); } else { ((IList <TProperty>)frame.ReturnValue).Add(value); } } else if (frame.IsPropertyEnumerable()) { Debug.Assert(frame.JsonPropertyInfo != null); Debug.Assert(frame.ReturnValue != null); if (frame.TempEnumerableValues != null) { ((IList <TProperty>)frame.TempEnumerableValues).Add(value); } else { ((IList <TProperty>)frame.JsonPropertyInfo.GetValueAsObject(frame.ReturnValue, options)).Add(value); } } else if (frame.IsDictionary()) { // todo: use TryAdd and throw JsonReaderException ((IDictionary <string, TProperty>)frame.ReturnValue).Add(frame.KeyName, value); } else if (frame.IsPropertyADictionary()) { Debug.Assert(frame.JsonPropertyInfo != null); Debug.Assert(frame.ReturnValue != null); ((IDictionary <string, TProperty>)frame.JsonPropertyInfo.GetValueAsObject(frame.ReturnValue, options)).Add(frame.KeyName, value); } else { Debug.Assert(frame.JsonPropertyInfo != null); frame.JsonPropertyInfo.SetValueAsObject(frame.ReturnValue, value, options); } }