public void ComplexNamedObject() { var json = new JsonBuilder() .WriteObject( j => j .WriteObject("object1", obj1 => obj1 .WriteProperty("property1", 1) ) ) .ToString(); Assert.AreEqual("{object1:{property1:1}}", json); }
public void MultipleNamedObjects() { var json = new JsonBuilder() .WriteObject( root => root .WriteObject("object1", obj1 => { }) .WriteObject("object2", obj2 => { }) ).ToString(); Assert.AreEqual( "{object1:{},object2:{}}", json ); }
internal void ToJson(JsonBuilder json) { // lines, points, bars: { // show: boolean // lineWidth: number // fill: boolean or number // fillColor: null or color/gradient // } json.WriteObject("lines", lines => lines .WritePropertyIf("show", GetField(Field.Show), GetField(Field.Show) != null) .WritePropertyIf("lineWidth", GetField(Field.LineWidth), GetField(Field.LineWidth) != null) .WritePropertyIf("fill", GetField(Field.Fill), GetField(Field.Fill) != null) .WritePropertyIf("fillColor", GetField(Field.FillColor), GetField(Field.FillColor) != null) ); }
internal void ToJson(JsonBuilder json) { // lines, points, bars: { // show: boolean // lineWidth: number // fill: boolean or number // fillColor: null or color/gradient // } json.WriteObject("lines", lines => lines .WritePropertyIf("show", GetField(Field.Show), GetField(Field.Show) != null) .WritePropertyIf("lineWidth", GetField(Field.LineWidth), GetField(Field.LineWidth) != null) .WritePropertyIf("fill", GetField(Field.Fill), GetField(Field.Fill) != null) .WritePropertyIf("fillColor", GetField(Field.FillColor), GetField(Field.FillColor) != null) ); }
internal void ToJson(JsonBuilder json) { // lines, points, bars: { // show: boolean // lineWidth: number // fill: boolean or number // fillColor: null or color/gradient // } json.WriteObject("bars", bars=>bars .WritePropertyIf("show", _fields[Field.Show], _fields[Field.Show] != null) .WritePropertyIf("lineWidth", _fields[Field.LineWidth], _fields[Field.LineWidth] != null) .WritePropertyIf("fill", _fields[Field.Fill], _fields[Field.Fill] != null) .WritePropertyIf("fillColor", _fields[Field.FillColor], _fields[Field.FillColor] != null) ); }
internal void ToJson(JsonBuilder json) { // lines, points, bars: { // show: boolean // lineWidth: number // fill: boolean or number // fillColor: null or color/gradient // } json.WriteObject("points", points => points .WritePropertyIf("show", _fields[Field.Show], _fields[Field.Show] != null) .WritePropertyIf("lineWidth", _fields[Field.LineWidth], _fields[Field.LineWidth] != null) .WritePropertyIf("fill", _fields[Field.Fill], _fields[Field.Fill] != null) .WritePropertyIf("fillColor", _fields[Field.FillColor], _fields[Field.FillColor] != null) .WritePropertyIf("radius", _fields[Field.Radius], _fields[Field.Radius] != null) ); }
internal void ToJson(JsonBuilder json) { //legend: { // show: boolean // labelFormatter: null or (fn: string, series object -> string) // labelBoxBorderColor: color // noColumns: number // position: "ne" or "nw" or "se" or "sw" // margin: number of pixels or [x margin, y margin] // backgroundColor: null or color // backgroundOpacity: number between 0 and 1 // container: null or jQuery object/DOM element/jQuery expression //} json.WriteObject("legend", legend => legend .WritePropertyIf("show", GetValue(Field.Show), GetValue(Field.Show) != null) .WritePropertyIf("position",GetValue(Field.Position), GetValue(Field.Position) != null ) ); }
internal void ToJson(JsonBuilder json) { //legend: { // show: boolean // labelFormatter: null or (fn: string, series object -> string) // labelBoxBorderColor: color // noColumns: number // position: "ne" or "nw" or "se" or "sw" // margin: number of pixels or [x margin, y margin] // backgroundColor: null or color // backgroundOpacity: number between 0 and 1 // container: null or jQuery object/DOM element/jQuery expression //} json.WriteObject("legend", legend => legend .WritePropertyIf("show", GetValue(Field.Show), GetValue(Field.Show) != null) .WritePropertyIf("position", GetValue(Field.Position), GetValue(Field.Position) != null) ); }
public void MultipleNamedComplexObjects() { var json = new JsonBuilder() .WriteObject(root => root .WriteObject("object1", obj1 => obj1 .WriteProperty("prop1", 1) .WriteProperty("prop2", 2) ) .WriteObject("object2", obj2 => obj2 .WriteProperty("prop1", 1) .WriteProperty("prop2", 2) ) ).ToString(); Assert.AreEqual( "{object1:{prop1:1,prop2:2},object2:{prop1:1,prop2:2}}", json ); }
internal void ToJson(JsonBuilder json) { json .WriteObject("xaxis", xaxis => xaxis .WritePropertyIf("mode", GetValue(Field.Mode), GetValue(Field.Mode) != null) .WritePropertyIf("timeformat", GetValue(Field.TimeFormat), GetValue(Field.TimeFormat) != null) .WritePropertyIf("min", GetValue(Field.Min), GetValue(Field.Min) != null) .WritePropertyIf("max", GetValue(Field.Max), GetValue(Field.Max) != null) ); }
public string ToJson() { var json = new JsonBuilder(); ToJson(json); return json.ToString(); }
internal void ToJson(JsonBuilder json) { json //.BeginObject() .WritePropertyIf( "color", _fields.ContainsKey(Field.Color) ? _fields[Field.Color] : null, _fields.ContainsKey(Field.Color) ) .WritePropertyIf( "label", _fields.ContainsKey(Field.Label) ? _fields[Field.Label] : null, _fields.ContainsKey(Field.Label) ) .WritePropertyIf( "xaxis", _fields.ContainsKey(Field.XAxis) ? _fields[Field.XAxis] : null, _fields.ContainsKey(Field.XAxis) ) .WritePropertyIf( "yaxis", _fields.ContainsKey(Field.YAxis) ? _fields[Field.YAxis] : null, _fields.ContainsKey(Field.YAxis) ) .WritePropertyIf( "clickable", _fields.ContainsKey(Field.Clickable) ? _fields[Field.Clickable] : null, _fields.ContainsKey(Field.Clickable) ) .WritePropertyIf( "hoverable", _fields.ContainsKey(Field.Hoverable) ? _fields[Field.Hoverable] : null, _fields.ContainsKey(Field.Hoverable) ) .WritePropertyIf( "shadowSize", _fields.ContainsKey(Field.ShadowSize) ? _fields[Field.ShadowSize] : null, _fields.ContainsKey(Field.ShadowSize) ); if (_lineOptions != null) { _lineOptions.ToJson(json); } if (_barOptions != null) { _barOptions.ToJson(json); } if (_pointOptions != null) { _pointOptions.ToJson(json); } }
public void SimpleNamedObject() { var json = new JsonBuilder() .WriteObject( m => m .WriteObject("object1", j => { } ) ) .ToString(); Assert.AreEqual("{object1:{}}", json); }
internal void ToJson(JsonBuilder json) { json //.BeginObject() .WritePropertyIf( "color", _fields.ContainsKey(Field.Color) ? _fields[Field.Color] : null, _fields.ContainsKey(Field.Color) ) .WritePropertyIf( "label", _fields.ContainsKey(Field.Label) ? _fields[Field.Label] : null, _fields.ContainsKey(Field.Label) ) .WritePropertyIf( "xaxis", _fields.ContainsKey(Field.XAxis) ? _fields[Field.XAxis] : null, _fields.ContainsKey(Field.XAxis) ) .WritePropertyIf( "yaxis", _fields.ContainsKey(Field.YAxis) ? _fields[Field.YAxis] : null, _fields.ContainsKey(Field.YAxis) ) .WritePropertyIf( "clickable", _fields.ContainsKey(Field.Clickable) ? _fields[Field.Clickable] : null, _fields.ContainsKey(Field.Clickable) ) .WritePropertyIf( "hoverable", _fields.ContainsKey(Field.Hoverable) ? _fields[Field.Hoverable] : null, _fields.ContainsKey(Field.Hoverable) ) .WritePropertyIf( "shadowSize", _fields.ContainsKey(Field.ShadowSize) ? _fields[Field.ShadowSize] : null, _fields.ContainsKey(Field.ShadowSize) ); if (_lineOptions != null) _lineOptions.ToJson(json); if (_barOptions != null) _barOptions.ToJson(json); if (_pointOptions != null) _pointOptions.ToJson(json); }
public void NestedNamedObjects() { var json = new JsonBuilder() .WriteObject(root => root .WriteObject("object1", m=>m .WriteProperty("property1", 1) .WriteObject("object1-1",n=>n .WriteProperty("property2",2) ) ) ) .ToString(); Assert.AreEqual( "{object1:{property1:1,object1-1:{property2:2}}}", json ); }
public void MultiplePropertiesTest() { var json = new JsonBuilder() .WriteObject( json2 => json2 .WriteProperty("property1", 1) .WriteProperty("property2", 2) ) .ToString(); Assert.AreEqual("{property1:1,property2:2}", json); }
public void CanCreate() { var json = new JsonBuilder(); Assert.IsNotNull(json); }
public void EmptyBuilder() { var json = new JsonBuilder().ToString(); Assert.AreEqual("", json); }