예제 #1
0
        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());
            }
        }
예제 #2
0
 public string Serialize(object obj, Filter filter)
 {
     using (var context = SerializingContext.Create(_serializer, filter))
     {
         SerializeMemberValue(obj, context);
         return(context.StringWriter.ToString());
     }
 }
예제 #3
0
 public void SerializeMemberValue(object memberValue, SerializingContext context)
 {
     if (memberValue is IEntityHandlerProvider provider)
     {
         provider.GetHandler().Serialize(context);
     }
     else
     {
         context.Serializer.Serialize(context.Writer, memberValue);
     }
 }
예제 #4
0
 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;
 }
예제 #5
0
 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();
        }