Beispiel #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 obj   = enumerator.Current;
                object value = enumerator2.Current;
                if (!flag)
                {
                    builder.Append(",");
                }
                string text = obj as string;
                if (text != null)
                {
                    PlayFabSimpleJson.SerializeString(text, builder);
                }
                else if (!PlayFabSimpleJson.SerializeValue(jsonSerializerStrategy, value, builder))
                {
                    return(false);
                }
                builder.Append(":");
                if (!PlayFabSimpleJson.SerializeValue(jsonSerializerStrategy, value, builder))
                {
                    return(false);
                }
                flag = false;
            }
            builder.Append("}");
            return(true);
        }
Beispiel #2
0
        private static bool SerializeValue(IJsonSerializerStrategy jsonSerializerStrategy, object value, StringBuilder builder)
        {
            bool   flag = true;
            string text = value as string;

            if (value == null)
            {
                builder.Append("null");
            }
            else if (text != null)
            {
                flag = PlayFabSimpleJson.SerializeString(text, builder);
            }
            else
            {
                IDictionary <string, object> dictionary = value as IDictionary <string, object>;
                Type   type = value.GetType();
                Type[] genericTypeArguments = ReflectionUtils.GetGenericTypeArguments(type);
                bool   flag2 = type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary <, >) && genericTypeArguments[0] == typeof(string);
                if (flag2)
                {
                    IDictionary dictionary2 = value as IDictionary;
                    flag = PlayFabSimpleJson.SerializeObject(jsonSerializerStrategy, dictionary2.Keys, dictionary2.Values, builder);
                }
                else if (dictionary != null)
                {
                    flag = PlayFabSimpleJson.SerializeObject(jsonSerializerStrategy, dictionary.Keys, dictionary.Values, builder);
                }
                else
                {
                    IDictionary <string, string> dictionary3 = value as IDictionary <string, string>;
                    if (dictionary3 != null)
                    {
                        flag = PlayFabSimpleJson.SerializeObject(jsonSerializerStrategy, dictionary3.Keys, dictionary3.Values, builder);
                    }
                    else
                    {
                        IEnumerable enumerable = value as IEnumerable;
                        if (enumerable != null)
                        {
                            flag = PlayFabSimpleJson.SerializeArray(jsonSerializerStrategy, enumerable, builder);
                        }
                        else if (PlayFabSimpleJson.IsNumeric(value))
                        {
                            flag = PlayFabSimpleJson.SerializeNumber(value, builder);
                        }
                        else if (value is bool)
                        {
                            builder.Append((!(bool)value) ? "false" : "true");
                        }
                        else
                        {
                            object value2;
                            flag = jsonSerializerStrategy.TrySerializeNonPrimitiveObject(value, out value2);
                            if (flag)
                            {
                                PlayFabSimpleJson.SerializeValue(jsonSerializerStrategy, value2, builder);
                            }
                        }
                    }
                }
            }
            return(flag);
        }