示例#1
0
        // Token: 0x060000B9 RID: 185 RVA: 0x000057B0 File Offset: 0x000039B0
        public static JsonValue ToJsonValue <T>(T ret)
        {
            if (ret == null)
            {
                return(null);
            }
            T t;

            if ((t = ret) is bool)
            {
                return(new JsonPrimitive((bool)((object)t)));
            }
            if ((t = ret) is byte)
            {
                return(new JsonPrimitive((byte)((object)t)));
            }
            if ((t = ret) is char)
            {
                return(new JsonPrimitive((char)((object)t)));
            }
            if ((t = ret) is decimal)
            {
                return(new JsonPrimitive((decimal)((object)t)));
            }
            if ((t = ret) is double)
            {
                return(new JsonPrimitive((double)((object)t)));
            }
            if ((t = ret) is float)
            {
                return(new JsonPrimitive((float)((object)t)));
            }
            if ((t = ret) is int)
            {
                return(new JsonPrimitive((int)((object)t)));
            }
            if ((t = ret) is long)
            {
                return(new JsonPrimitive((long)((object)t)));
            }
            if ((t = ret) is sbyte)
            {
                return(new JsonPrimitive((sbyte)((object)t)));
            }
            if ((t = ret) is short)
            {
                return(new JsonPrimitive((short)((object)t)));
            }
            string value;

            if ((value = (ret as string)) != null)
            {
                return(new JsonPrimitive(value));
            }
            if ((t = ret) is uint)
            {
                return(new JsonPrimitive((uint)((object)t)));
            }
            if ((t = ret) is ulong)
            {
                return(new JsonPrimitive((ulong)((object)t)));
            }
            if ((t = ret) is ushort)
            {
                return(new JsonPrimitive((ushort)((object)t)));
            }
            if ((t = ret) is DateTime)
            {
                return(new JsonPrimitive((DateTime)((object)t)));
            }
            if ((t = ret) is DateTimeOffset)
            {
                return(new JsonPrimitive((DateTimeOffset)((object)t)));
            }
            if ((t = ret) is Guid)
            {
                return(new JsonPrimitive((Guid)((object)t)));
            }
            if ((t = ret) is TimeSpan)
            {
                return(new JsonPrimitive((TimeSpan)((object)t)));
            }
            Uri value2;

            if ((value2 = (ret as Uri)) != null)
            {
                return(new JsonPrimitive(value2));
            }
            IEnumerable <KeyValuePair <string, object> > enumerable = ret as IEnumerable <KeyValuePair <string, object> >;

            if (enumerable != null)
            {
                return(new JsonObject(JsonValue.ToJsonPairEnumerable(enumerable)));
            }
            IEnumerable enumerable2 = ret as IEnumerable;

            if (enumerable2 != null)
            {
                return(new JsonArray(JsonValue.ToJsonValueEnumerable(enumerable2)));
            }
            if (!(ret is IEnumerable))
            {
                PropertyInfo[] properties = ret.GetType().GetProperties();
                Dictionary <string, object> dictionary = new Dictionary <string, object>();
                foreach (PropertyInfo propertyInfo in properties)
                {
                    dictionary.Add(propertyInfo.Name, propertyInfo.GetValue(ret, null));
                }
                if (dictionary.Count > 0)
                {
                    return(new JsonObject(JsonValue.ToJsonPairEnumerable(dictionary)));
                }
            }
            throw new NotSupportedException(string.Format("Unexpected parser return type: {0}", ret.GetType()));
        }
示例#2
0
        // Token: 0x06000A10 RID: 2576 RVA: 0x000210AC File Offset: 0x0001F2AC
        public static JsonValue ToJsonValue <T>(T ret)
        {
            if (ret == null)
            {
                return(null);
            }
            T t;

            if ((t = ret) is bool)
            {
                bool value = (bool)((object)t);
                return(new JsonPrimitive(value));
            }
            if ((t = ret) is byte)
            {
                byte value2 = (byte)((object)t);
                return(new JsonPrimitive(value2));
            }
            if ((t = ret) is char)
            {
                char value3 = (char)((object)t);
                return(new JsonPrimitive(value3));
            }
            if ((t = ret) is decimal)
            {
                decimal value4 = (decimal)((object)t);
                return(new JsonPrimitive(value4));
            }
            if ((t = ret) is double)
            {
                double value5 = (double)((object)t);
                return(new JsonPrimitive(value5));
            }
            if ((t = ret) is float)
            {
                float value6 = (float)((object)t);
                return(new JsonPrimitive(value6));
            }
            if ((t = ret) is int)
            {
                int value7 = (int)((object)t);
                return(new JsonPrimitive(value7));
            }
            if ((t = ret) is long)
            {
                long value8 = (long)((object)t);
                return(new JsonPrimitive(value8));
            }
            if ((t = ret) is sbyte)
            {
                sbyte value9 = (sbyte)((object)t);
                return(new JsonPrimitive(value9));
            }
            if ((t = ret) is short)
            {
                short value10 = (short)((object)t);
                return(new JsonPrimitive(value10));
            }
            string value11;

            if ((value11 = (ret as string)) != null)
            {
                return(new JsonPrimitive(value11));
            }
            if ((t = ret) is uint)
            {
                uint value12 = (uint)((object)t);
                return(new JsonPrimitive(value12));
            }
            if ((t = ret) is ulong)
            {
                ulong value13 = (ulong)((object)t);
                return(new JsonPrimitive(value13));
            }
            if ((t = ret) is ushort)
            {
                ushort value14 = (ushort)((object)t);
                return(new JsonPrimitive(value14));
            }
            if ((t = ret) is DateTime)
            {
                DateTime value15 = (DateTime)((object)t);
                return(new JsonPrimitive(value15));
            }
            if ((t = ret) is DateTimeOffset)
            {
                DateTimeOffset value16 = (DateTimeOffset)((object)t);
                return(new JsonPrimitive(value16));
            }
            if ((t = ret) is Guid)
            {
                Guid value17 = (Guid)((object)t);
                return(new JsonPrimitive(value17));
            }
            if ((t = ret) is TimeSpan)
            {
                TimeSpan value18 = (TimeSpan)((object)t);
                return(new JsonPrimitive(value18));
            }
            Uri value19;

            if ((value19 = (ret as Uri)) != null)
            {
                return(new JsonPrimitive(value19));
            }
            IEnumerable <KeyValuePair <string, object> > enumerable = ret as IEnumerable <KeyValuePair <string, object> >;

            if (enumerable != null)
            {
                return(new JsonObject(JsonValue.ToJsonPairEnumerable(enumerable)));
            }
            IEnumerable enumerable2 = ret as IEnumerable;

            if (enumerable2 != null)
            {
                return(new JsonArray(JsonValue.ToJsonValueEnumerable(enumerable2)));
            }
            if (!(ret is IEnumerable))
            {
                PropertyInfo[] properties = ret.GetType().GetProperties();
                Dictionary <string, object> dictionary = new Dictionary <string, object>();
                foreach (PropertyInfo propertyInfo in properties)
                {
                    dictionary.Add(propertyInfo.Name, propertyInfo.GetValue(ret, null).IsNull("null"));
                }
                if (dictionary.Count > 0)
                {
                    return(new JsonObject(JsonValue.ToJsonPairEnumerable(dictionary)));
                }
            }
            throw new NotSupportedException(string.Format("Unexpected parser return type: {0}", ret.GetType()));
        }