(WriteContext context, in TDictionary value, bool hasGenerics)
| 48 | } |
| 49 | |
| 50 | public override void WriteData(WriteContext context, in TDictionary value, bool hasGenerics) |
| 51 | { |
| 52 | Serializer<TKey> keySerializer = context.TypeResolver.GetSerializer<TKey>(); |
| 53 | Serializer<TValue> valueSerializer = context.TypeResolver.GetSerializer<TValue>(); |
| 54 | TypeInfo keyTypeInfo = context.TypeResolver.GetTypeInfo<TKey>(); |
| 55 | TypeInfo valueTypeInfo = context.TypeResolver.GetTypeInfo<TValue>(); |
| 56 | TDictionary map = value ?? CreateMap(0); |
| 57 | context.Writer.WriteVarUInt32((uint)map.Count); |
| 58 | if (map.Count == 0) |
| 59 | { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | bool trackKeyRef = context.TrackRef && keyTypeInfo.IsRefType; |
| 64 | bool trackValueRef = context.TrackRef && valueTypeInfo.IsRefType; |
| 65 | bool keyDeclared = hasGenerics && !TypeResolver.NeedToWriteTypeInfoForField(keyTypeInfo); |
| 66 | bool valueDeclared = hasGenerics && !TypeResolver.NeedToWriteTypeInfoForField(valueTypeInfo); |
| 67 | bool keyDynamicType = keyTypeInfo.IsDynamicType; |
| 68 | bool valueDynamicType = valueTypeInfo.IsDynamicType; |
| 69 | |
| 70 | KeyValuePair<TKey, TValue>[] pairs = SnapshotPairs(map); |
| 71 | if (keyDynamicType || valueDynamicType) |
| 72 | { |
| 73 | WriteDynamicMapPairs( |
| 74 | pairs, |
| 75 | context, |
| 76 | hasGenerics, |
| 77 | trackKeyRef, |
| 78 | trackValueRef, |
| 79 | keyDeclared, |
| 80 | valueDeclared, |
| 81 | keyDynamicType, |
| 82 | valueDynamicType, |
| 83 | keyTypeInfo, |
| 84 | valueTypeInfo, |
| 85 | keySerializer, |
| 86 | valueSerializer); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | int index = 0; |
| 91 | while (index < pairs.Length) |
| 92 | { |
| 93 | KeyValuePair<TKey, TValue> pair = pairs[index]; |
| 94 | bool keyIsNull = context.TypeResolver.IsNoneObject(keyTypeInfo, pair.Key); |
| 95 | bool valueIsNull = context.TypeResolver.IsNoneObject(valueTypeInfo, pair.Value); |
| 96 | if (keyIsNull || valueIsNull) |
| 97 | { |
| 98 | byte header = 0; |
| 99 | if (trackKeyRef) |
| 100 | { |
| 101 | header |= DictionaryBits.TrackingKeyRef; |
| 102 | } |
| 103 | |
| 104 | if (trackValueRef) |
| 105 | { |
| 106 | header |= DictionaryBits.TrackingValueRef; |
| 107 | } |
nothing calls this directly
no test coverage detected