Beispiel #1
0
        private static bool SerializeValue(IJsonSerializerStrategy jsonSerializerStrategy, object value, StringBuilder builder)
        {
            bool   success     = true;
            string stringValue = value as string;

            if (stringValue != null)
            {
                success = SerializeString(stringValue, builder);
            }
            else
            {
                IDictionary <string, object> dict = value as IDictionary <string, object>;
                if (dict != null)
                {
                    success = SerializeObject(jsonSerializerStrategy, dict.Keys, dict.Values, builder);
                }
                else
                {
                    IDictionary <string, string> stringDictionary = value as IDictionary <string, string>;
                    if (stringDictionary != null)
                    {
                        success = SerializeObject(jsonSerializerStrategy, stringDictionary.Keys, stringDictionary.Values, builder);
                    }
                    else
                    {
                        IEnumerable enumerableValue = value as IEnumerable;
                        if (enumerableValue != null)
                        {
                            success = SerializeArray(jsonSerializerStrategy, enumerableValue, builder);
                        }
                        else if (IsNumeric(value))
                        {
                            success = SerializeNumber(value, builder);
                        }
                        else if (value is bool)
                        {
                            builder.Append((bool)value ? "true" : "false");
                        }
                        else if (value == null)
                        {
                            builder.Append("null");
                        }
                        else
                        {
                            object serializedObject;
                            success = jsonSerializerStrategy.TrySerializeNonPrimitiveObject(value, out serializedObject);
                            if (success)
                            {
                                SerializeValue(jsonSerializerStrategy, serializedObject, builder);
                            }
                        }
                    }
                }
            }

            return(success);
        }
Beispiel #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);
        }
Beispiel #3
0
        private static bool SerializeValue(IJsonSerializerStrategy jsonSerializerStrategy, object value, StringBuilder builder)
        {
            bool   flag    = true;
            string aString = value as string;

            if (aString != null)
            {
                flag = SimpleJson.SimpleJson.SerializeString(aString, builder);
            }
            else
            {
                IDictionary <string, object> dictionary1 = value as IDictionary <string, object>;
                if (dictionary1 != null)
                {
                    flag = SimpleJson.SimpleJson.SerializeObject(jsonSerializerStrategy, (IEnumerable)dictionary1.Keys, (IEnumerable)dictionary1.Values, builder);
                }
                else
                {
                    IDictionary <string, string> dictionary2 = value as IDictionary <string, string>;
                    if (dictionary2 != null)
                    {
                        flag = SimpleJson.SimpleJson.SerializeObject(jsonSerializerStrategy, (IEnumerable)dictionary2.Keys, (IEnumerable)dictionary2.Values, builder);
                    }
                    else
                    {
                        IEnumerable anArray = value as IEnumerable;
                        if (anArray != null)
                        {
                            flag = SimpleJson.SimpleJson.SerializeArray(jsonSerializerStrategy, anArray, builder);
                        }
                        else if (SimpleJson.SimpleJson.IsNumeric(value))
                        {
                            flag = SimpleJson.SimpleJson.SerializeNumber(value, builder);
                        }
                        else if (value is bool)
                        {
                            builder.Append(!(bool)value ? "false" : "true");
                        }
                        else if (value == null)
                        {
                            builder.Append("null");
                        }
                        else
                        {
                            object output;
                            flag = jsonSerializerStrategy.TrySerializeNonPrimitiveObject(value, out output);
                            if (flag)
                            {
                                SimpleJson.SimpleJson.SerializeValue(jsonSerializerStrategy, output, builder);
                            }
                        }
                    }
                }
            }
            return(flag);
        }
Beispiel #4
0
        private static bool SerializeValue(IJsonSerializerStrategy jsonSerializerStrategy, object value, StringBuilder builder)
        {
            object obj2;
            bool   flag    = true;
            string aString = value as string;

            if (aString != null)
            {
                return(SerializeString(aString, builder));
            }
            IDictionary <string, object> dictionary = value as IDictionary <string, object>;

            if (dictionary != null)
            {
                return(SerializeObject(jsonSerializerStrategy, dictionary.Keys, dictionary.Values, builder));
            }
            IDictionary <string, string> dictionary2 = value as IDictionary <string, string>;

            if (dictionary2 != null)
            {
                return(SerializeObject(jsonSerializerStrategy, dictionary2.Keys, dictionary2.Values, builder));
            }
            IEnumerable anArray = value as IEnumerable;

            if (anArray != null)
            {
                return(SerializeArray(jsonSerializerStrategy, anArray, builder));
            }
            if (IsNumeric(value))
            {
                return(SerializeNumber(value, builder));
            }
            if (value is bool)
            {
                builder.Append(!((bool)value) ? "false" : "true");
                return(flag);
            }
            if (value == null)
            {
                builder.Append("null");
                return(flag);
            }
            flag = jsonSerializerStrategy.TrySerializeNonPrimitiveObject(value, out obj2);
            if (flag)
            {
                SerializeValue(jsonSerializerStrategy, obj2, builder);
            }
            return(flag);
        }
Beispiel #5
0
        private static bool SerializeValue(IJsonSerializerStrategy jsonSerializerStrategy, object value, StringBuilder builder)
        {
            var success = true;

            if (value is string stringValue)
            {
                return(SerializeString(stringValue, builder));
            }
            if (IsChar(value))
            {
                return(SerializeString(((char)value).ToString(), builder));
            }

            switch (value)
            {
            case IDictionary <string, object> dict:
                return(SerializeObject(jsonSerializerStrategy, dict.Keys, dict.Values, builder));

            case IDictionary <string, string> stringDictionary:
                return(SerializeObject(jsonSerializerStrategy, stringDictionary.Keys, stringDictionary.Values, builder));

            case IEnumerable enumerableValue:
                return(SerializeArray(jsonSerializerStrategy, enumerableValue, builder));
            }

            if (IsNumeric(value))
            {
                return(SerializeNumber(value, builder));
            }

            if (value is bool b)
            {
                builder.Append(b ? "true" : "false");
            }
            else if (value is null)
            {
                builder.Append("null");
            }
            else
            {
                success = jsonSerializerStrategy.TrySerializeNonPrimitiveObject(value, out var serializedObject);
                if (success)
                {
                    SerializeValue(jsonSerializerStrategy, serializedObject, builder);
                }
            }
            return(success);
        }
Beispiel #6
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);
        }