Exemplo n.º 1
0
        private static bool SerializeObject(IJsonSerializerStrategy jsonSerializerStrategy, IEnumerable keys, IEnumerable values, StringBuilder builder)
        {
            builder.Append("{");
            IEnumerator enumerator  = keys.GetEnumerator();
            IEnumerator enumerator2 = values.GetEnumerator();
            bool        flag        = true;

            while (enumerator.MoveNext() && enumerator2.MoveNext())
            {
                object current  = enumerator.Current;
                object current2 = enumerator2.Current;
                if (!flag)
                {
                    builder.Append(",");
                }
                string text = current as string;
                if (text != null)
                {
                    SimpleJson.SerializeString(text, builder);
                }
                else if (!SimpleJson.SerializeValue(jsonSerializerStrategy, current2, builder))
                {
                    return(false);
                }
                builder.Append(":");
                if (!SimpleJson.SerializeValue(jsonSerializerStrategy, current2, builder))
                {
                    return(false);
                }
                flag = false;
            }
            builder.Append("}");
            return(true);
        }
Exemplo n.º 2
0
        private static bool SerializeValue(IJsonSerializerStrategy jsonSerializerStrategy, object value, StringBuilder builder)
        {
            bool   flag = true;
            string text = value as string;

            if (text != null)
            {
                flag = SimpleJson.SerializeString(text, builder);
            }
            else
            {
                IDictionary <string, object> dictionary = value as IDictionary <string, object>;
                if (dictionary != null)
                {
                    flag = SimpleJson.SerializeObject(jsonSerializerStrategy, dictionary.Keys, dictionary.Values, builder);
                }
                else
                {
                    IDictionary <string, string> dictionary2 = value as IDictionary <string, string>;
                    if (dictionary2 != null)
                    {
                        flag = SimpleJson.SerializeObject(jsonSerializerStrategy, dictionary2.Keys, dictionary2.Values, builder);
                    }
                    else
                    {
                        IEnumerable enumerable = value as IEnumerable;
                        if (enumerable != null)
                        {
                            flag = SimpleJson.SerializeArray(jsonSerializerStrategy, enumerable, builder);
                        }
                        else if (SimpleJson.IsNumeric(value))
                        {
                            flag = SimpleJson.SerializeNumber(value, builder);
                        }
                        else if (value is bool)
                        {
                            builder.Append((!(bool)value) ? "false" : "true");
                        }
                        else if (value == null)
                        {
                            builder.Append("null");
                        }
                        else
                        {
                            object value2;
                            flag = jsonSerializerStrategy.TrySerializeNonPrimitiveObject(value, out value2);
                            if (flag)
                            {
                                SimpleJson.SerializeValue(jsonSerializerStrategy, value2, builder);
                            }
                        }
                    }
                }
            }
            return(flag);
        }