CreateObject() public method

public CreateObject ( Jayrock.Json.Conversion.ImportContext context, JsonReader reader ) : ObjectConstructionResult
context Jayrock.Json.Conversion.ImportContext
reader JsonReader
return ObjectConstructionResult
Esempio n. 1
0
 public void ConstructionWithTail()
 {
     ObjectConstructor ctor = new ObjectConstructor(typeof(Point));
     ImportContext context = JsonConvert.CreateImportContext();
     const string json = "{ y: 456, z: 789, x: 123 }";
     ObjectConstructionResult result = ctor.CreateObject(context, JsonText.CreateReader(json));
     Point point = (Point) result.Object;
     Assert.AreEqual(123, point.X);
     Assert.AreEqual(456, point.Y);
     NamedJsonBuffer[] tail = JsonBuffer.From(result.TailReader).GetMembersArray();
     Assert.AreEqual(1, tail.Length);
     NamedJsonBuffer z = tail[0];
     Assert.AreEqual("z", z.Name);
     Assert.AreEqual(789, z.Buffer.GetNumber().ToInt32());
 }
Esempio n. 2
0
 public void Construction()
 {
     ObjectConstructor ctor = new ObjectConstructor(typeof(Point));
     ImportContext context = JsonConvert.CreateImportContext();
     const string json = "{ y: 456, x: 123 }";
     ObjectConstructionResult result = ctor.CreateObject(context, JsonText.CreateReader(json));
     Point point = (Point)result.Object;
     Assert.AreEqual(123, point.X);
     Assert.AreEqual(456, point.Y);
     Assert.AreEqual(0, JsonBuffer.From(result.TailReader).GetMemberCount());
 }
Esempio n. 3
0
 private Thing CreateThing(string json)
 {
     ObjectConstructor ctor = new ObjectConstructor(typeof(Thing));
     ImportContext context = JsonConvert.CreateImportContext();
     ObjectConstructionResult result = ctor.CreateObject(context, JsonText.CreateReader(json));
     return (Thing) result.Object;
 }
Esempio n. 4
0
 public void CannotCreateIfNoneConstructorsMatch()
 {
     ObjectConstructor ctor = new ObjectConstructor(typeof(Point));
     ImportContext context = JsonConvert.CreateImportContext();
     ctor.CreateObject(context, JsonText.CreateReader("{ z: x: 123 }"));
 }
Esempio n. 5
0
 public void ValueTypeWithDefaultConstructorConstruction()
 {
     ObjectConstructor constructor = new ObjectConstructor(typeof(ValueThing));
     ObjectConstructionResult result = constructor.CreateObject(new ImportContext(), JsonText.CreateReader("{foo:bar}"));
     Assert.IsInstanceOfType(typeof(ValueThing), result.Object);
     JsonReader tail = result.TailReader;
     tail.ReadToken(JsonTokenClass.Object);
     Assert.AreEqual("foo", tail.ReadMember());
     Assert.AreEqual("bar", tail.ReadString());
     tail.ReadToken(JsonTokenClass.EndObject);
 }