internal static void WriteValues(IValueWriter writer, IEnumerable <LdValue> values) { var arr = writer.Array(); foreach (var v in values) { LdValueConverter.WriteJsonValue(v, arr); } arr.End(); }
private void WriteStructs(IValueWriter w, List <TestStruct> structs) { var arr = w.Array(); for (var i = 0; i < structs.Count; i++) { WriteTestStruct(w, structs[i]); } arr.End(); }
internal static void WriteStrings(IValueWriter writer, IEnumerable <string> values) { var arr = writer.Array(); foreach (var v in values) { arr.String(v); } arr.End(); }
private void WriteInts(IValueWriter w, List <int> ints) { var arr = w.Array(); for (var i = 0; i < ints.Count; i++) { w.Int(ints[i]); } arr.End(); }
private void WriteBools(IValueWriter w, List <bool> bools) { var arr = w.Array(); for (var i = 0; i < bools.Count; i++) { w.Bool(bools[i]); } arr.End(); }
internal static void WriteClauses(IValueWriter writer, IEnumerable <Clause> clauses) { var arr = writer.Array(); foreach (var c in clauses) { var clauseObj = arr.Object(); clauseObj.Name("attribute").String(c.Attribute.AttributeName); clauseObj.Name("op").String(c.Op.Name); WriteValues(clauseObj.Name("values"), c.Values); clauseObj.Name("negate").Bool(c.Negate); clauseObj.End(); } arr.End(); }
public static void WriteJsonValue(LdValue value, IValueWriter writer) { switch (value.Type) { case LdValueType.Null: writer.Null(); break; case LdValueType.Bool: writer.Bool(value.AsBool); break; case LdValueType.Number: var asInt = value.AsInt; var asDouble = value.AsDouble; if ((double)asInt == asDouble) { writer.Int(asInt); } else { writer.Double(asDouble); } break; case LdValueType.String: writer.String(value.AsString); break; case LdValueType.Array: var arr = writer.Array(); foreach (var v in value.List) { WriteJsonValue(v, arr); } arr.End(); break; case LdValueType.Object: var obj = writer.Object(); foreach (var kv in value.Dictionary) { WriteJsonValue(kv.Value, obj.Name(kv.Key)); } obj.End(); break; } }
public void WriteJson(object instance, IValueWriter writer) { switch (instance) { case null: writer.Null(); break; case bool value: writer.Bool(value); break; case int value: writer.Int(value); break; case long value: writer.Long(value); break; case float value: writer.Double(value); break; case double value: writer.Double(value); break; case string value: writer.String(value); break; case IReadOnlyDictionary <string, object> dict: var obj = writer.Object(); foreach (var kv in dict) { WriteJson(kv.Value, obj.Name(kv.Key)); } obj.End(); break; case IReadOnlyDictionary <object, object> dict: var obj1 = writer.Object(); foreach (var kv in dict) { WriteJson(kv.Value, obj1.Name(kv.Key.ToString())); } obj1.End(); break; case IEnumerable <object> list: var arr = writer.Array(); foreach (var o in list) { WriteJson(o, arr); } arr.End(); break; default: throw new ArgumentException(string.Format("ConvertSimpleTypes does not support type {0}", instance.GetType())); } }