MCPcopy Create free account
hub / github.com/apache/fory / TryWritePayload

Method TryWritePayload

csharp/src/Fory/CollectionSerializers.cs:339–379  ·  view source on GitHub ↗
(object value, WriteContext context, bool hasGenerics)

Source from the content-addressed store, hash-verified

337 }
338
339 public static bool TryWritePayload(object value, WriteContext context, bool hasGenerics)
340 {
341 if (value is IDictionary dictionary)
342 {
343 NullableKeyDictionary<object, object?> map = new();
344 foreach (DictionaryEntry entry in dictionary)
345 {
346 map.Add(entry.Key, entry.Value);
347 }
348
349 context.TypeResolver.GetSerializer<NullableKeyDictionary<object, object?>>().WriteData(context, map, false);
350 return true;
351 }
352
353 Type valueType = value.GetType();
354 if (TryGetListLikeEnumerable(value, valueType, out IEnumerable? listLike, out int countHint))
355 {
356 List<object?> values = countHint >= 0 ? new List<object?>(countHint) : [];
357 foreach (object? item in listLike!)
358 {
359 values.Add(item);
360 }
361
362 context.TypeResolver.GetSerializer<List<object?>>().WriteData(context, values, hasGenerics);
363 return true;
364 }
365
366 if (!IsSet(valueType))
367 {
368 return false;
369 }
370
371 HashSet<object?> set = [];
372 foreach (object? item in (IEnumerable)value)
373 {
374 set.Add(item);
375 }
376
377 context.TypeResolver.GetSerializer<HashSet<object?>>().WriteData(context, set, hasGenerics);
378 return true;
379 }
380
381 public static List<object?> ReadListPayload(ReadContext context)
382 {

Callers 1

WriteAnyPayloadMethod · 0.80

Calls 3

WriteDataMethod · 0.65
GetTypeMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected