Exemplo n.º 1
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var points = (List <Point>)value;

            if (points.Any())
            {
                var converter = new PointConverter();

                writer.WriteStartArray();

                foreach (var point in points)
                {
                    converter.WriteJson(writer, point.Coordinates, serializer);
                }

                writer.WriteEndArray();
            }
        }
Exemplo n.º 2
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var points = (List<Point>)value;

            if (points.Any())
            {
                var converter = new PointConverter();

                writer.WriteStartArray();

                foreach (var point in points)
                {
                    converter.WriteJson(writer, point.Coordinates, serializer);
                }

                writer.WriteEndArray();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Not implemented yet.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="objectType"></param>
        /// <param name="existingValue"></param>
        /// <param name="serializer"></param>
        /// <returns></returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var        jArcs = serializer.Deserialize <JArray>(reader);
            List <Arc> arcs  = new List <Arc>();

            if (jArcs == null || jArcs.Count == 0)
            {
                return(arcs);
            }
            foreach (var arc in jArcs.Children())
            {
                Arc a = new Arc();
                List <GeographicPosition> positions = new List <GeographicPosition>();
                var converter = new PointConverter();
                foreach (JArray coordinate in arc)
                {
                    GeographicPosition position;
                    if (coordinate.Count == 2)
                    {
                        position = new GeographicPosition((double)coordinate[1], (double)coordinate[0]);
                    }
                    else if (coordinate.Count == 3)
                    {
                        return((IPosition) new GeographicPosition((double)coordinate[1], (double)coordinate[0], (double)coordinate[2]));
                    }
                    else
                    {
                        throw new JsonException(string.Format("Coordinate must have two or three components ({0} found).",
                                                              coordinate.Count));
                    }
                    positions.Add(position);
                }
                a.Positions = positions;
                arcs.Add(a);
            }
            return(arcs);
        }