public static string SerializeChanges(List <Change> changes) { using (var context = SerializingContext.Create(null, null)) { var writer = context.Writer; writer.WriteStartArray(); foreach (var change in changes) { writer.WriteStartObject(); writer.WritePropertyName("op"); writer.WriteValue(change.Type.ToString().ToLowerInvariant()); writer.WritePropertyName("path"); writer.WriteValue(change.Path); switch (change.Type) { case ChangeType.Add: case ChangeType.Replace: writer.WritePropertyName("value"); writer.WriteRawValue(change.Serialized); break; } writer.WriteEndObject(); } writer.WriteEndArray(); return(context.StringWriter.ToString()); } }
public string Serialize(object obj, Filter filter) { using (var context = SerializingContext.Create(_serializer, filter)) { SerializeMemberValue(obj, context); return(context.StringWriter.ToString()); } }
public void SerializeMemberValue(object memberValue, SerializingContext context) { if (memberValue is IEntityHandlerProvider provider) { provider.GetHandler().Serialize(context); } else { context.Serializer.Serialize(context.Writer, memberValue); } }
public static SerializingContext Create(JsonSerializer serializer, Filter filter) { var result = new SerializingContext(); result.StringWriter = new StringWriter(); result.Writer = new JsonTextWriter(result.StringWriter); // result.Writer.Formatting = Formatting.Indented; result.Writer.Formatting = Formatting.None; result.Serializer = serializer; result.Filter = filter; return result; }
public void Serialize(SerializingContext context) { context.Writer.WriteStartObject(); foreach (var item in _inner) { if (context.Filter.IsOk(item.Value, _typeConfig.ValueType.Type, null)) { context.Writer.WritePropertyName(item.Key); _manager.SerializeMemberValue(item.Value, context); } } context.Writer.WriteEndObject(); }
public void Serialize(SerializingContext context) { context.Writer.WriteStartObject(); foreach (var member in _values) { if (context.Filter.IsOk(Proxy, _typeConfig.Type, member.Key)) { context.Writer.WritePropertyName(member.Key); _manager.SerializeMemberValue(member.Value, context); } } context.Writer.WriteEndObject(); }