Esempio n. 1
0
        public static string Serialize <K, V>(Dictionary <K, V> dict)
        {
            if (!dict.Any())
            {
                return("{}");
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("{");

            foreach (KeyValuePair <K, V> kvp in dict)
            {
                sb.Append("(");
                sb.Append(kvp.Key);
                sb.Append(",");
                IDescription idv = kvp.Value as IDescription;
                if (idv != null)
                {
                    sb.Append(idv.Serialize());
                }
                else
                {
                    sb.Append(kvp.Value);
                }
                sb.Append(")");
                sb.Append(",");
            }

            sb.Remove(sb.Length - 1, 1);

            sb.Append("}");

            return(sb.ToString());
        }
Esempio n. 2
0
        public static string Serialize <T>(IEnumerable <T> list)
        {
            if (!list.Any())
            {
                return("[]");
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("[");

            foreach (T t in list)
            {
                IDescription idt = t as IDescription;
                if (idt != null)
                {
                    sb.Append(idt.Serialize());
                }
                else
                {
                    sb.Append(t);
                }
                sb.Append(",");
            }

            sb.Remove(sb.Length - 1, 1);

            sb.Append("]");

            return(sb.ToString());
        }