Пример #1
0
    private static bool SerializeValue(IJsonSerializerStrategy jsonSerializerStrategy, object value, StringBuilder builder)
    {
        bool   flag = true;
        string text = value as string;

        if (text != null)
        {
            flag = SimpleJsonTool.SerializeString(text, builder);
        }
        else
        {
            IDictionary <string, object> dictionary = value as IDictionary <string, object>;
            if (dictionary != null)
            {
                flag = SimpleJsonTool.SerializeObject(jsonSerializerStrategy, dictionary.Keys, dictionary.Values, builder);
            }
            else
            {
                IDictionary <string, string> dictionary2 = value as IDictionary <string, string>;
                if (dictionary2 != null)
                {
                    flag = SimpleJsonTool.SerializeObject(jsonSerializerStrategy, dictionary2.Keys, dictionary2.Values, builder);
                }
                else
                {
                    IEnumerable enumerable = value as IEnumerable;
                    if (enumerable != null)
                    {
                        flag = SimpleJsonTool.SerializeArray(jsonSerializerStrategy, enumerable, builder);
                    }
                    else if (SimpleJsonTool.IsNumeric(value))
                    {
                        flag = SimpleJsonTool.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)
                        {
                            SimpleJsonTool.SerializeValue(jsonSerializerStrategy, value2, builder);
                        }
                    }
                }
            }
        }
        return(flag);
    }
Пример #2
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;
        bool        result;

        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)
            {
                SimpleJsonTool.SerializeString(text, builder);
            }
            else if (!SimpleJsonTool.SerializeValue(jsonSerializerStrategy, current2, builder))
            {
                result = false;
                return(result);
            }
            builder.Append(":");
            if (SimpleJsonTool.SerializeValue(jsonSerializerStrategy, current2, builder))
            {
                flag = false;
                continue;
            }
            result = false;
            return(result);
        }
        builder.Append("}");
        result = true;
        return(result);
    }