internal override void WriteObjectData(object obj, SerializationContext context, StringBuilder sb) { // else then we deserialize the data inside sb.Append(NodeParser.WrappingStart); sb.Append('\n'); context.TabPadding++; SerializerUtils.GetTabSpaces(context.TabPadding, sb); context.Register(obj, out int newRef); WriteHeader(sb, newRef); sb.Append('\n'); IEnumerable cast = (IEnumerable)obj; int index = 0; foreach (object element in cast) { Type elementType = element.GetType(); if (context.WithPropertiesComments) { sb.Append('\n'); sb.Append('\n'); SerializerUtils.GetTabSpaces(context.TabPadding, sb); sb.Append($"# [{ index }] #"); } ISerializerInternal elementSerialiazer = SerializerDependencies.SerializerCollection.GetOrAdd(elementType); sb.Append('\n'); SerializerUtils.GetTabSpaces(context.TabPadding, sb); elementSerialiazer.SerializeInternal(element, context, sb); sb.Append(SerializerConsts.DATA_SEPARATOR); index++; } sb.Remove(sb.Length - 1, 1); sb.Append('\n'); context.TabPadding--; SerializerUtils.GetTabSpaces(context.TabPadding, sb); sb.Append(NodeParser.WrappingEnd); }
internal override void WriteObjectData(object obj, SerializationContext context, StringBuilder sb) { // else then we deserialize the data inside sb.Append(NodeParser.WrappingStart); sb.Append('\n'); context.TabPadding++; SerializerUtils.GetTabSpaces(context.TabPadding, sb); context.Register(obj, out int newRef); WriteHeader(sb, newRef); sb.Append('\n'); IDictionary cast = (IDictionary)obj; ICollection keys = cast.Keys; int index = 0; if (keys.Count != 0) { foreach (object key in keys) { Type keyType = key.GetType(); var value = cast[key]; Type valueType = value.GetType(); if (context.WithPropertiesComments) { sb.Append('\n'); sb.Append('\n'); SerializerUtils.GetTabSpaces(context.TabPadding, sb); sb.Append($"# [{ index }] #"); } ISerializerInternal keySerialiazer = SerializerDependencies.SerializerCollection.GetOrAdd(keyType); ISerializerInternal valueSerialiazer = SerializerDependencies.SerializerCollection.GetOrAdd(valueType); sb.Append('\n'); SerializerUtils.GetTabSpaces(context.TabPadding, sb); // kv pair sb.Append('{'); sb.Append('\n'); context.TabPadding++; // key SerializerUtils.GetTabSpaces(context.TabPadding, sb); sb.Append("# key #"); sb.Append('\n'); SerializerUtils.GetTabSpaces(context.TabPadding, sb); keySerialiazer.SerializeInternal(key, context, sb); sb.Append(SerializerConsts.DATA_SEPARATOR); sb.Append('\n'); // value SerializerUtils.GetTabSpaces(context.TabPadding, sb); sb.Append("# value #"); sb.Append('\n'); SerializerUtils.GetTabSpaces(context.TabPadding, sb); valueSerialiazer.SerializeInternal(value, context, sb); context.TabPadding--; sb.Append('\n'); SerializerUtils.GetTabSpaces(context.TabPadding, sb); sb.Append('}'); sb.Append(SerializerConsts.DATA_SEPARATOR); SerializerUtils.GetTabSpaces(context.TabPadding, sb); index++; } sb.Remove(sb.Length - 2, 2); } sb.Append('\n'); context.TabPadding--; SerializerUtils.GetTabSpaces(context.TabPadding, sb); sb.Append(NodeParser.WrappingEnd); }