Example #1
0
        public void TestComplex()
        {
            var p = new PointComplex()
            {
                X = 10, Y = 20
            };

            var json = Json.Format(p);

            Assert.Equal("\"10,20\"", json);

            var p2 = Json.Parse <PointComplex>(json);

            Assert.Equal(p.X, p2.X);
            Assert.Equal(p.Y, p2.Y);
        }
Example #2
0
 private static PointComplex ParseJson(IJsonReader r)
 {
     if (r.GetLiteralKind() == LiteralKind.String)
     {
         var parts = ((string)r.GetLiteralString()).Split(',');
         if (parts.Length == 2)
         {
             var pt = new PointComplex()
             {
                 X = int.Parse(parts[0], CultureInfo.InvariantCulture),
                 Y = int.Parse(parts[0], CultureInfo.InvariantCulture),
             };
             r.NextToken();
             return pt;
         }
     }
     throw new InvalidDataException("Invalid point");
 }
Example #3
0
 private static PointComplex ParseJson(IJsonReader r)
 {
     if (r.GetLiteralKind() == LiteralKind.String)
     {
         var parts = ((string)r.GetLiteralString()).Split(',');
         if (parts.Length == 2)
         {
             var pt = new PointComplex()
             {
                 X = int.Parse(parts[0], CultureInfo.InvariantCulture),
                 Y = int.Parse(parts[1], CultureInfo.InvariantCulture),
             };
             r.NextToken();
             return(pt);
         }
     }
     throw new InvalidDataException("Invalid point");
 }
Example #4
0
        public void TestComplex()
        {
            var p = new PointComplex() { X = 10, Y = 20 };

            var json = Json.Format(p);

            Assert.AreEqual(json, "\"10,20\"");

            var p2 = Json.Parse<PointComplex>(json);

            Assert.Equals(p.X, p2.X);
            Assert.Equals(p.Y, p2.Y);
        }