示例#1
0
        public static JObject ToJObject(object input)
        {
            try
            {
                //already a string
                if (input.GetType() == typeof(string))
                {
                    var s = input as string;
                    if (!string.IsNullOrWhiteSpace(s))
                    {
                        if (s.Length == 0)
                        {
                            return(null);
                        }
                        if (s[0] == '{')
                        {
                            return(JObject.Parse(s));
                        }
                    }
                }

                return(JObject.FromObject(input, GetJsonSerializer()));
            }
            catch (Exception ex)
            {
                //if the original was an exception, convert to SerialError...
                if (input as Exception != null)
                {
                    var ret = JObject.FromObject(SerialError.FromObject(input), GetJsonSerializer());
                    ret["__CONVERTED"]        = new JValue("Converted to a SerialError");
                    ret["__CONVERTED_REASON"] = new JValue(ex.Message);
                    return(ret);
                }

                throw;
            }
        }
示例#2
0
        private static JObject HandleError(object input)
        {
            var ex = SerialError.FromObject(input);

            if (ex == null)
            {
                return(null);
            }

            var ret = ToJObject(ex);

            try
            {
                if (App.UseDebugMode)
                {
                    ret["FullExceptionDetails"] = JS.ToJObject(input);
                }
            }
            catch (Exception)
            {
                ret["FullExceptionDetails"] = new JValue(ex.ToString());
            }
            return(ret);
        }