示例#1
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if(!(value is Entry))
            {
                serializer.Serialize(writer, value);
                return;
            }

            Entry entry = (Entry)value;
            writer.WriteStartObject();
            serializer.WriteProperty(writer, Utils.NameOf(() => entry.ContentId), entry.ContentId);
            serializer.WriteProperty(writer, Utils.NameOf(() => entry.RelativePath), entry.RelativePath);
            serializer.WriteProperty(writer, Utils.NameOf(() => entry.IsOpen), entry.IsOpen);
            serializer.WriteProperty(writer, Utils.NameOf(() => entry.Name), entry.Name);
            serializer.WriteProperty(writer, Utils.NameOf(() => entry.Type), entry.Type);

            writer.WritePropertyName(Utils.NameOf(() => entry.Children));
            if (entry.IsOpen)
            {
                serializer.Serialize(writer, entry.Children);
            }
            else
            {
                writer.WriteStartArray();
                writer.WriteEndArray();
            }
            writer.WritePropertyName("has-" + Utils.NameOf(() => entry.Children));
            writer.WriteValue(entry.Children.Count > 0);
            writer.WriteEndObject();
        }