SuperMap.Web.iServerJava6R.ServerGeometry.ToJson C# (CSharp) Method

ToJson() static private method

static private ToJson ( ServerGeometry serverGeometry ) : string
serverGeometry ServerGeometry
return string
        internal static string ToJson(ServerGeometry serverGeometry)
        {
            if (serverGeometry == null)
            {
                return null;
            }

            string json = "{";
            List<string> list = new List<string>();

            list.Add(string.Format(CultureInfo.InvariantCulture, "\"type\":\"{0}\"", serverGeometry.Type));
            list.Add(string.Format(CultureInfo.InvariantCulture, "\"id\":{0}", serverGeometry.ID));

            if (serverGeometry.Parts != null && serverGeometry.Parts.Count > 0)
            {
                List<string> parts = new List<string>();
                foreach (int i in serverGeometry.Parts)
                {
                    parts.Add(i.ToString(CultureInfo.InvariantCulture));
                }
                list.Add(string.Format(CultureInfo.InvariantCulture, "\"parts\":[{0}]", string.Join(",", parts.ToArray())));
            }
            else
            {
                list.Add(string.Format(CultureInfo.InvariantCulture, "\"parts\":null"));
            }
            if (serverGeometry.Points != null && serverGeometry.Points.Count > 0)
            {
                List<string> ps = new List<string>();
                foreach (Point2D p in serverGeometry.Points)
                {
                    string pointJson;
                    if (serverGeometry.Type == ServerGeometryType.LINEM)
                    {
                        pointJson = JsonHelper.FromPoint2DWithTag(p, "measure", true);
                    }
                    else
                    {
                        pointJson = JsonHelper.FromPoint2D(p);
                    }
                    ps.Add(pointJson);
                }
                list.Add(string.Format(CultureInfo.InvariantCulture, "\"points\":[{0}]", string.Join(",", ps.ToArray())));
            }
            else
            {
                list.Add(string.Format(CultureInfo.InvariantCulture, "\"points\":null"));
            }

            if (serverGeometry.Style != null)
            {
                list.Add(string.Format(CultureInfo.InvariantCulture, "\"style\":{0}", ServerStyle.ToJson(serverGeometry.Style)));
            }
            else
            {
                list.Add(string.Format(CultureInfo.InvariantCulture, "\"style\":null"));
            }

            if (serverGeometry.Type == ServerGeometryType.LINEM)
            {
                list.Add(string.Format(CultureInfo.InvariantCulture, string.Format("\"length\":{0}", ((ServerRoute)serverGeometry).Length.ToStringEx())));
                list.Add(string.Format(CultureInfo.InvariantCulture, string.Format("\"maxM\":{0}", ((ServerRoute)serverGeometry).MaxM.ToStringEx())));
                list.Add(string.Format(CultureInfo.InvariantCulture, string.Format("\"minM\":{0}", ((ServerRoute)serverGeometry).MinM.ToStringEx())));
            }

            json += string.Join(",", list.ToArray());
            json += "}";
            return json;
        }