SuperMap.Web.ISDotNET6.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("\"feature\":{0}", (int)serverGeometry.Feature));
            list.Add(string.Format("\"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());
                }
                list.Add(string.Format("\"parts\":[{0}]", string.Join(",", parts.ToArray())));
            }
            else
            {
                list.Add(string.Format("\"parts\":[]"));
            }
            if (serverGeometry.Point2Ds != null && serverGeometry.Point2Ds.Count > 0)
            {
                List<string> ps = new List<string>();
                foreach (Point2D p in serverGeometry.Point2Ds)
                {
                    ps.Add(JsonHelper.FromPoint2D(p));
                }
                list.Add(string.Format("\"points\":[{0}]", string.Join(",", ps.ToArray())));
            }
            else
            {
                list.Add(string.Format("\"points\":null"));
            }
            json += string.Join(",", list.ToArray());
            json += "}";
            return json;
        }