Example #1
0
        private List <JsonItem> JsonDecodeFromDictionary(IEnumerable item, JsonItem parent, HashSet <object> recursion)
        {
            List <JsonItem> objects = new List <JsonItem>();

            foreach (object key in item)
            {
                object value = null;
                string name  = null;
                Type   type  = key.GetType();
                if (key is DictionaryEntry entry)
                {
                    value = entry.Value;
                    name  = entry.Key.ToString();
                }
                else
                {
                    if (key is KeyValuePair <string, object> pair)
                    {
                        value = pair.Value;
                        name  = pair.Key.ToString();
                    }
                }
                JsonItem jitem = this.GetJsonItemByNameValue(name, value, parent, recursion);
                if (jitem != null)
                {
                    objects.Add(jitem);
                }
            }
            return(objects);
        }
Example #2
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = null;
            JsonItem jitem = this.Find(binder.Name);
            bool     flag  = jitem == null;
            bool     result2;

            if (flag)
            {
                result  = null;
                result2 = true;
            }
            else
            {
                bool flag2 = jitem.ObjectType == JsonItemType.OBJ_ARRAY || jitem.ObjectType == JsonItemType.OBJ_OBJECT;
                if (flag2)
                {
                    result = jitem;
                }
                else
                {
                    result = jitem.Value;
                }
                result2 = true;
            }
            return(result2);
        }
Example #3
0
        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            JsonItem jitem = this.Find(binder.Name);
            bool     flag  = jitem != null;

            if (flag)
            {
                jitem.Value = value;
            }
            else
            {
                if (value is JsonItem jsitem)
                {
                    jsitem.Name   = binder.Name;
                    jsitem.Parent = this;
                    jsitem.Index  = this.SubItems.Count;
                    this.SubItems.Add(jsitem);
                }
                else
                {
                    jitem = new JsonItem
                    {
                        Parent = this,
                        Name   = binder.Name
                    };
                    JsonDecoder.DecodeFrom(value, jitem);
                    jitem.Index = this.SubItems.Count;
                    this.SubItems.Add(jitem);
                }
            }
            return(true);
        }
Example #4
0
        public static JsonItem DecodeFrom(object item, JsonItem baseitem = null)
        {
            JsonDecoder jparser = new JsonDecoder();
            JsonItem    jitem   = baseitem;

            if (jitem == null)
            {
                jitem = new JsonItem();
            }
            HashSet <object> recursion = new HashSet <object>();
            JsonItem         parent    = jitem.Parent;

            if (parent != null && parent.ObjectType == JsonItemType.OBJ_ARRAY)
            {
                jitem.ObjectType = JsonItemType.OBJ_ARRAYITEM;
            }
            else
            {
                JsonItem parent2 = jitem.Parent;
                if (parent2 != null && parent2.ObjectType == JsonItemType.OBJ_OBJECT)
                {
                    jitem.ObjectType = JsonItemType.OBJ_VARIANT;
                }
            }
            if (jitem == null)
            {
                jitem = new JsonItem();
            }
            if (item.IsArray())
            {
                jitem.ObjectType = JsonItemType.OBJ_ARRAY;
                jitem.SubItems   = jparser.JsonDecodeFromArray((IList)item, jitem, recursion);
            }
            else
            {
                if (item.IsObject() || item.IsDictionary())
                {
                    jitem.ObjectType = JsonItemType.OBJ_OBJECT;
                    if (item is IDictionary || item is IDictionary <string, object> )
                    {
                        jitem.SubItems = jparser.JsonDecodeFromDictionary((IEnumerable)item, jitem, recursion);
                    }
                    else
                    {
                        jitem.SubItems = jparser.JsonDecodeFromObject(item, jitem, recursion);
                    }
                }
                else
                {
                    jitem.Value = item;
                }
            }
            recursion.Clear();
            return(jitem);
        }
Example #5
0
      public static string Encode(JsonItem jsonItem, int formatting = 2, bool printcomment = true)
      {
          JsonEncoder jsonEncoder = new JsonEncoder
          {
              formattingtype = formatting
          };

          jsonEncoder.printComment = printcomment;
          jsonEncoder.rootItem     = jsonItem;
          return(jsonEncoder.EncodeJson(jsonItem));
      }
Example #6
0
        private List <JsonItem> JsonDecodeFromArray(IList array, JsonItem parent, HashSet <object> recursion)
        {
            List <JsonItem> objects = new List <JsonItem>();

            for (int i = 0; i < array.Count; i++)
            {
                object   value = array[i];
                JsonItem jitem = this.GetJsonItemByNameValue(null, value, parent, recursion);
                if (jitem != null)
                {
                    objects.Add(jitem);
                }
            }
            return(objects);
        }
Example #7
0
 public void AddSubItem(JsonItem item)
 {
     if (item.ObjectType == JsonItemType.OBJ_OBJECT)
     {
         for (int i = 0; i < item.SubItems.Count; i++)
         {
             item.SubItems[i].Index = this.SubItems.Count;
             this.SubItems.Add(item.SubItems[i]);
             item.SubItems[i].Parent = this;
         }
     }
     else
     {
         item.Parent = this;
         this.SubItems.Add(item);
         item.Index = this.SubItems.Count - 1;
     }
 }
Example #8
0
        public JsonItem Evulate(string evulator)
        {
            string[] alls = evulator.Split(new char[]
            {
                '.'
            });
            JsonItem item = this;

            for (int i = 0; i < alls.Length; i++)
            {
                item = item.Find(alls[i]);
                bool flag = item == null;
                if (flag)
                {
                    return(null);
                }
            }
            return(item);
        }
Example #9
0
 public object this[int index]
 {
     get
     {
         if (this.ObjectType == JsonItemType.OBJ_ARRAY)
         {
             if (index < 0 || index > this.SubItems.Count)
             {
                 return(null);
             }
             JsonItem jitem = this.SubItems[index];
             bool     flag3 = jitem != null;
             if (flag3)
             {
                 return(jitem.Value);
             }
         }
         return(null);
     }
     set
     {
         if (this.ObjectType == JsonItemType.OBJ_ARRAY)
         {
             bool flag2 = index <0 || index> this.SubItems.Count;
             if (!flag2)
             {
                 JsonItem jitem = this.SubItems[index];
                 bool     flag3 = jitem != null;
                 if (flag3)
                 {
                     jitem.Value = value;
                 }
             }
         }
     }
 }
Example #10
0
        private List <JsonItem> JsonDecodeFromObject(object item, JsonItem parent, HashSet <object> recursion)
        {
            Type type = item.GetType();

            MemberInfo[]    members = type.GetMembers(BindingFlags.Instance | BindingFlags.Public);
            List <JsonItem> objects = new List <JsonItem>();

            foreach (MemberInfo member in members)
            {
                bool flag = member.MemberType != MemberTypes.Field && member.MemberType != MemberTypes.Property;
                if (!flag)
                {
                    object        value = null;
                    string        name  = member.Name;
                    JsonAttribute jattribut;
                    bool          flag2 = (jattribut = (member.GetCustomAttribute(typeof(JsonAttribute)) as JsonAttribute)) != null;
                    if (flag2)
                    {
                        bool notMapped = jattribut.NotMapped;
                        if (notMapped)
                        {
                            goto IL_13B;
                        }
                        bool flag3 = !string.IsNullOrEmpty(jattribut.TagName);
                        if (flag3)
                        {
                            name = jattribut.TagName;
                        }
                    }
                    PropertyInfo property;
                    bool         flag4 = (property = (member as PropertyInfo)) != null;
                    if (flag4)
                    {
                        bool flag5 = !property.CanRead;
                        if (flag5)
                        {
                            goto IL_13B;
                        }
                        bool flag6 = property.GetIndexParameters().Length != 0;
                        if (flag6)
                        {
                            goto IL_13B;
                        }
                        value = property.GetValue(item);
                    }
                    else
                    {
                        FieldInfo field;
                        bool      flag7 = (field = (member as FieldInfo)) != null;
                        if (flag7)
                        {
                            value = field.GetValue(item);
                        }
                    }
                    JsonItem jitem = this.GetJsonItemByNameValue(name, value, parent, recursion);
                    bool     flag8 = jitem == null;
                    if (!flag8)
                    {
                        objects.Add(jitem);
                    }
                }
                IL_13B :;
            }
            return(objects);
        }
Example #11
0
        private JsonItem GetJsonItemByNameValue(string name, object value, JsonItem parent, HashSet <object> recursion)
        {
            JsonItem result;

            if (this.CheckOrAddRecursion(value, recursion))
            {
                result = null;
            }
            else
            {
                JsonItem jitem = new JsonItem
                {
                    Name     = name,
                    NameQuot = '"',
                    Parent   = parent
                };
                if (value.IsArray())
                {
                    jitem.ObjectType = JsonItemType.OBJ_ARRAY;
                    jitem.SubItems   = this.JsonDecodeFromArray((IList)value, jitem, recursion);
                }
                else
                {
                    if (value.IsObject())
                    {
                        jitem.ObjectType = JsonItemType.OBJ_OBJECT;
                        if (value is IDictionary || value is IDictionary <string, object> )
                        {
                            jitem.SubItems = this.JsonDecodeFromDictionary((IEnumerable)value, jitem, recursion);
                        }
                        else
                        {
                            jitem.SubItems = this.JsonDecodeFromObject(value, jitem, recursion);
                        }
                    }
                    else
                    {
                        if (value == null)
                        {
                            jitem.ObjectType = ((parent.ObjectType == JsonItemType.OBJ_OBJECT) ? JsonItemType.OBJ_VARIANT : JsonItemType.OBJ_ARRAYITEM);
                            jitem.Value      = null;
                        }
                        else
                        {
                            jitem.ObjectType = ((parent.ObjectType == JsonItemType.OBJ_OBJECT) ? JsonItemType.OBJ_VARIANT : JsonItemType.OBJ_ARRAYITEM);
                            if (value.IsNumericType() || value is bool)
                            {
                                jitem.ValueQuot = '\0';
                                jitem.Value     = value;
                            }
                            else
                            {
                                jitem.ValueQuot = '"';
                                jitem.Value     = value.ToString();
                            }
                        }
                    }
                }
                result = jitem;
            }
            return(result);
        }
Example #12
0
        private JsonItem DecodeJson(string inputText)
        {
            this.input = inputText;
            JsonItem jsonItem = new JsonItem
            {
                NameQuot  = '\0',
                ValueQuot = '\0',
                IsParse   = true
            };
            char          quotchar = '\0';
            bool          quoted   = false;
            StringBuilder builder  = new StringBuilder();
            int           i        = 0;

            while (i < this.input.Length)
            {
                char cur  = this.input[i];
                bool flag = quoted;
                if (flag)
                {
                    bool flag2 = quotchar == cur;
                    if (flag2)
                    {
                        jsonItem.ObjectType = JsonItemType.OBJ_SINGLE;
                        jsonItem.Value      = builder.ToString();
                        quoted = false;
                        break;
                    }
                    builder.Append(cur);
                }
                char c = cur;
                if (c <= '"')
                {
                    switch (c)
                    {
                    case '\t':
                    case '\n':
                    case '\r':
                        break;

                    case '\v':
                    case '\f':
                        goto IL_127;

                    default:
                        if (c != ' ')
                        {
                            if (c != '"')
                            {
                                goto IL_127;
                            }
                            goto IL_D8;
                        }
                        break;
                    }
                }
                else
                {
                    if (c == '\'')
                    {
                        goto IL_D8;
                    }
                    if (c == '[')
                    {
                        this.startid        = i;
                        jsonItem.ObjectType = JsonItemType.OBJ_ARRAY;
                        jsonItem.SubItems   = this.JsonDecode(JsonItemType.OBJ_NONE, null);
                        return(jsonItem);
                    }
                    if (c != '{')
                    {
                        goto IL_127;
                    }
                    this.startid        = i;
                    jsonItem.ObjectType = JsonItemType.OBJ_OBJECT;
                    jsonItem.SubItems   = this.JsonDecode(JsonItemType.OBJ_NONE, null);
                    return(jsonItem);
                }
IL_12D:
                i++;
                continue;
IL_D8:
                quoted   = true;
                quotchar = cur;
                goto IL_12D;
IL_127:
                return(null);
            }
            bool flag3 = quoted;

            if (flag3)
            {
                return(null);
            }
            return(jsonItem);
        }
Example #13
0
        private List <JsonItem> JsonDecode(JsonItemType objtype, JsonItem parent)
        {
            StringBuilder key              = new StringBuilder();
            StringBuilder value            = new StringBuilder();
            StringBuilder comment          = new StringBuilder();
            bool          inquot           = false;
            bool          quoted           = false;
            bool          isspec           = false;
            bool          splitterFound    = false;
            bool          inlinecomment    = false;
            bool          multilinecomment = false;
            int           lineoffset       = 0;
            char          quotchar         = '\0';
            JsonItem      lastitem         = new JsonItem
            {
                Parent    = parent,
                NameQuot  = '\0',
                ValueQuot = '\0'
            };
            List <JsonItem> items    = new List <JsonItem>();
            List <JsonItem> comments = new List <JsonItem>();

            for (int i = this.startid; i < this.input.Length; i++)
            {
                char cur  = this.input[i];
                char next = (i + 1 < this.input.Length) ? this.input[i + 1] : '\0';
                bool flag = inlinecomment || multilinecomment;
                if (flag)
                {
                    bool flag2 = inlinecomment;
                    if (flag2)
                    {
                        bool flag3 = cur == '\r' && next == '\n';
                        if (flag3)
                        {
                            goto IL_87B;
                        }
                    }
                    bool flag4 = (inlinecomment && cur == '\n') || (multilinecomment && cur == '*' && next == '/');
                    if (flag4)
                    {
                        bool flag5 = multilinecomment;
                        if (flag5)
                        {
                            i++;
                        }
                        bool flag6 = !this.skipComment;
                        if (flag6)
                        {
                            JsonItem commentItem = new JsonItem
                            {
                                LineOffset = lineoffset,
                                Value      = comment.ToString(),
                                ObjectType = (inlinecomment ? JsonItemType.OBJ_COMMENT_SINGLELINE : JsonItemType.OBJ_COMMENT_MULTILINE),
                                Parent     = parent,
                                NameQuot   = '\0',
                                ValueQuot  = '\0',
                                Index      = items.Count
                            };
                            bool flag7 = key.Length > 0 || splitterFound;
                            if (flag7)
                            {
                                comments.Add(commentItem);
                            }
                            else
                            {
                                items.Add(commentItem);
                            }
                            comment.Clear();
                        }
                        inlinecomment    = false;
                        multilinecomment = false;
                    }
                    else
                    {
                        bool flag8 = !this.skipComment;
                        if (flag8)
                        {
                            comment.Append(cur);
                        }
                    }
                }
                else
                {
                    bool flag9 = isspec;
                    if (flag9)
                    {
                        bool flag10 = this.DecodeUnicode && (cur == 'u' || cur == 'U') && i + 5 < this.input.Length;
                        if (flag10)
                        {
                            bool  contn = true;
                            int[] nums  = new int[4];
                            for (int j = 1; j < 5; j++)
                            {
                                char ucur   = this.input[i + j];
                                bool flag11 = !Uri.IsHexDigit(ucur);
                                if (flag11)
                                {
                                    contn = false;
                                    break;
                                }
                                nums[j - 1] = Uri.FromHex(ucur);
                            }
                            bool flag12 = contn;
                            if (flag12)
                            {
                                int formula = nums[0] * 16 * 16 * 16 + nums[1] * 16 * 16 + nums[2] * 16 + nums[3];
                                i  += 4;
                                cur = (char)formula;
                            }
                        }
                        bool flag13 = splitterFound;
                        if (flag13)
                        {
                            value.Append(cur);
                        }
                        else
                        {
                            key.Append(cur);
                        }
                        isspec = false;
                    }
                    else
                    {
                        bool flag14 = cur == '\\' && !isspec;
                        if (flag14)
                        {
                            isspec = true;
                        }
                        else
                        {
                            bool flag15 = cur == '/';
                            if (flag15)
                            {
                                bool flag16 = next == '/';
                                if (flag16)
                                {
                                    inlinecomment = true;
                                    i++;
                                    goto IL_87B;
                                }
                                bool flag17 = next == '*';
                                if (flag17)
                                {
                                    multilinecomment = true;
                                    i++;
                                    goto IL_87B;
                                }
                            }
                            bool flag18 = inquot;
                            if (flag18)
                            {
                                bool flag19 = cur == quotchar;
                                if (flag19)
                                {
                                    inquot = false;
                                    quoted = true;
                                    bool flag20 = objtype == JsonItemType.OBJ_ARRAY;
                                    if (flag20)
                                    {
                                        lastitem.ValueQuot = quotchar;
                                    }
                                    else
                                    {
                                        bool flag21 = objtype == JsonItemType.OBJ_OBJECT;
                                        if (flag21)
                                        {
                                            bool flag22 = splitterFound;
                                            if (flag22)
                                            {
                                                lastitem.ValueQuot = quotchar;
                                            }
                                            else
                                            {
                                                lastitem.NameQuot = quotchar;
                                            }
                                        }
                                    }
                                    goto IL_87B;
                                }
                                bool flag23 = !splitterFound;
                                if (flag23)
                                {
                                    key.Append(cur);
                                }
                                else
                                {
                                    value.Append(cur);
                                }
                            }
                            else
                            {
                                bool flag24 = cur == '"' || cur == '\'';
                                if (flag24)
                                {
                                    quotchar = cur;
                                    inquot   = true;
                                    goto IL_87B;
                                }
                            }
                            bool flag25 = !inquot;
                            if (flag25)
                            {
                                char c = cur;
                                if (c <= ':')
                                {
                                    if (c <= ' ')
                                    {
                                        switch (c)
                                        {
                                        case '\t':
                                        case '\n':
                                        case '\r':
                                            break;

                                        case '\v':
                                        case '\f':
                                            goto IL_842;

                                        default:
                                            if (c != ' ')
                                            {
                                                goto IL_842;
                                            }
                                            break;
                                        }
                                        bool flag26 = cur == '\n' || (cur == '\r' && next != '\n');
                                        if (flag26)
                                        {
                                            lineoffset++;
                                        }
                                    }
                                    else if (c != ',')
                                    {
                                        if (c != ':')
                                        {
                                            goto IL_842;
                                        }
                                        bool flag27 = splitterFound || objtype == JsonItemType.OBJ_ARRAY || objtype == JsonItemType.OBJ_NONE;
                                        if (flag27)
                                        {
                                            this.stopFailure = true;
                                            return(null);
                                        }
                                        lastitem.Name = key.ToString();
                                        splitterFound = true;
                                        quoted        = false;
                                        inquot        = false;
                                    }
                                    else
                                    {
                                        bool flag28 = !splitterFound && objtype == JsonItemType.OBJ_OBJECT;
                                        if (flag28)
                                        {
                                            this.stopFailure = true;
                                            return(null);
                                        }
                                        bool flag29 = objtype == JsonItemType.OBJ_ARRAY;
                                        if (flag29)
                                        {
                                            bool flag30 = key.Length > 0 || quoted;
                                            if (flag30)
                                            {
                                                lastitem.Value      = key.ToString();
                                                lastitem.ObjectType = JsonItemType.OBJ_ARRAYITEM;
                                            }
                                        }
                                        else
                                        {
                                            bool flag31 = objtype == JsonItemType.OBJ_OBJECT;
                                            if (flag31)
                                            {
                                                bool flag32 = value.Length > 0 || quoted;
                                                if (flag32)
                                                {
                                                    lastitem.Value      = value.ToString();
                                                    lastitem.ObjectType = JsonItemType.OBJ_VARIANT;
                                                }
                                            }
                                        }
                                        lastitem.Index = items.Count;
                                        items.Add(lastitem);
                                        bool flag33 = comments.Count > 0;
                                        if (flag33)
                                        {
                                            items.AddRange(comments);
                                            comments.Clear();
                                        }
                                        key.Clear();
                                        value.Clear();
                                        inquot        = false;
                                        quoted        = false;
                                        splitterFound = false;
                                        lastitem      = new JsonItem
                                        {
                                            NameQuot  = '\0',
                                            ValueQuot = '\0',
                                            Parent    = parent
                                        };
                                    }
                                }
                                else
                                {
                                    if (c <= ']')
                                    {
                                        if (c != '[')
                                        {
                                            if (c != ']')
                                            {
                                                goto IL_842;
                                            }
                                            goto IL_570;
                                        }
                                    }
                                    else if (c != '{')
                                    {
                                        if (c != '}')
                                        {
                                            goto IL_842;
                                        }
                                        goto IL_570;
                                    }
                                    bool flag34 = !splitterFound && key.Length > 0;
                                    if (flag34)
                                    {
                                        this.stopFailure = true;
                                        return(null);
                                    }
                                    bool flag35 = value.Length > 0;
                                    if (flag35)
                                    {
                                        this.stopFailure = true;
                                        return(null);
                                    }
                                    this.startid = i + 1;
                                    this.depth++;
                                    bool flag36 = cur == '{';
                                    if (flag36)
                                    {
                                        bool flag37 = !splitterFound && objtype == JsonItemType.OBJ_OBJECT;
                                        if (flag37)
                                        {
                                            this.stopFailure = true;
                                            return(null);
                                        }
                                        this.depth_object++;
                                        lastitem.ObjectType = JsonItemType.OBJ_OBJECT;
                                        lastitem.SubItems   = this.JsonDecode(JsonItemType.OBJ_OBJECT, lastitem);
                                    }
                                    else
                                    {
                                        this.depth_array++;
                                        lastitem.ObjectType = JsonItemType.OBJ_ARRAY;
                                        lastitem.SubItems   = this.JsonDecode(JsonItemType.OBJ_ARRAY, lastitem);
                                    }
                                    bool flag38 = this.stopFailure;
                                    if (flag38)
                                    {
                                        return(null);
                                    }
                                    i = this.startid;
                                    goto IL_879;
IL_570:
                                    bool flag39 = (objtype == JsonItemType.OBJ_OBJECT && !splitterFound && key.Length > 0) || (value.Length > 0 && objtype == JsonItemType.OBJ_ARRAY);
                                    if (flag39)
                                    {
                                        this.stopFailure = true;
                                        return(null);
                                    }
                                    this.startid = i;
                                    bool flag40 = cur == '}';
                                    if (flag40)
                                    {
                                        this.depth_object--;
                                    }
                                    else
                                    {
                                        this.depth_array--;
                                    }
                                    this.depth--;
                                    bool flag41 = this.depth_array < 0 || this.depth_object < 0 || this.depth < 0;
                                    if (flag41)
                                    {
                                        this.stopFailure = true;
                                        return(null);
                                    }
                                    bool flag42 = objtype == JsonItemType.OBJ_ARRAY;
                                    if (flag42)
                                    {
                                        bool flag43 = key.Length > 0;
                                        if (flag43)
                                        {
                                            lastitem.ObjectType = JsonItemType.OBJ_ARRAYITEM;
                                            lastitem.Value      = key.ToString();
                                        }
                                    }
                                    else
                                    {
                                        bool flag44 = objtype == JsonItemType.OBJ_OBJECT;
                                        if (flag44)
                                        {
                                            bool flag45 = value.Length > 0;
                                            if (flag45)
                                            {
                                                lastitem.ObjectType = JsonItemType.OBJ_VARIANT;
                                                lastitem.Value      = value.ToString();
                                            }
                                        }
                                    }
                                    lastitem.Index = items.Count;
                                    items.Add(lastitem);
                                    bool flag46 = comments.Count > 0;
                                    if (flag46)
                                    {
                                        items.AddRange(comments);
                                        comments.Clear();
                                    }
                                    return(items);
                                }
IL_879:
                                goto IL_87A;
IL_842:
                                if (!quoted)
                                {
                                    if (splitterFound)
                                    {
                                        value.Append(cur);
                                    }
                                    else
                                    {
                                        key.Append(cur);
                                    }
                                    goto IL_879;
                                }
                                this.stopFailure = true;
                                return(null);
                            }
                            IL_87A :;
                        }
                    }
                }
                IL_87B :;
            }
            return(lastitem.SubItems);
        }
Example #14
0
        public JsonItem Find(string name)
        {
            bool     flag = this.ObjectType != JsonItemType.OBJ_ARRAY && this.ObjectType != JsonItemType.OBJ_OBJECT;
            JsonItem result2;

            if (flag)
            {
                result2 = null;
            }
            else
            {
                Match  match      = Regex.Match(name, "([\\w\\d]+)?\\[(\\d+|l|f|L|F)\\]$");
                int    arrayIndex = -1;
                bool   success    = match.Success;
                string newname;
                if (success)
                {
                    string result = match.Result("${2}");
                    if (result != "f" && result != "F" && result != "l" && result != "L")
                    {
                        arrayIndex = int.Parse(result);
                    }
                    else
                    {
                        if (result == "f" || result == "F")
                        {
                            arrayIndex = 0;
                        }
                        else
                        {
                            arrayIndex = -2;
                        }
                    }
                    newname = match.Result("${1}");
                    if (newname == "${1}")
                    {
                        newname = null;
                    }
                }
                else
                {
                    newname = name;
                }
                if (newname == null)
                {
                    if (this.ObjectType != JsonItemType.OBJ_ARRAY || arrayIndex >= this.SubItems.Count)
                    {
                        result2 = null;
                    }
                    else
                    {
                        if (arrayIndex == -2)
                        {
                            arrayIndex = this.SubItems.Count - 1;
                        }
                        if (arrayIndex < 0)
                        {
                            result2 = null;
                        }
                        else
                        {
                            result2 = this.SubItems[arrayIndex];
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < this.SubItems.Count; i++)
                    {
                        JsonItem sub   = this.SubItems[i];
                        bool     flag9 = sub.ObjectType != JsonItemType.OBJ_ARRAYITEM && sub.ObjectType != JsonItemType.OBJ_OBJECT && sub.ObjectType != JsonItemType.OBJ_ARRAY && sub.ObjectType != JsonItemType.OBJ_VARIANT;
                        if (!flag9)
                        {
                            if (sub.ObjectType == JsonItemType.OBJ_ARRAY && sub.Name == newname)
                            {
                                if (arrayIndex == -2)
                                {
                                    arrayIndex = sub.SubItems.Count - 1;
                                }
                                bool flag12 = arrayIndex >= 0;
                                if (!flag12)
                                {
                                    return(sub);
                                }
                                if (arrayIndex >= sub.SubItems.Count)
                                {
                                    return(null);
                                }
                                return(sub.SubItems[arrayIndex]);
                            }
                            else
                            {
                                if (sub.Name == name)
                                {
                                    return(sub);
                                }
                            }
                        }
                    }
                    result2 = null;
                }
            }
            return(result2);
        }
Example #15
0
        public void ExportTo <T>(ref T obj) where T : class
        {
            bool flag = obj == null;

            if (!flag)
            {
                if (!obj.IsObject())
                {
                    bool flag3 = this.ObjectType == JsonItemType.OBJ_ARRAY || this.ObjectType == JsonItemType.OBJ_OBJECT;
                    if (flag3)
                    {
                        object tempobj = null;
                        if (this.ObjectType == JsonItemType.OBJ_ARRAY)
                        {
                            bool flag5 = obj.IsArray();
                            if (flag5)
                            {
                                bool flag6 = obj is Array;
                                if (flag6)
                                {
                                    Array array = obj as Array;
                                    bool  flag7 = array.Length < this.SubItems.Count;
                                    if (flag7)
                                    {
                                        JsonItem.Resize(ref array, this.SubItems.Count);
                                    }
                                    obj = (array as T);
                                }
                            }
                            IDictionary idict;
                            bool        flag8 = (idict = (obj as IDictionary)) != null;
                            if (flag8)
                            {
                                object[] nobj = new object[this.SubItems.Count];
                                idict.Add(this.Name, nobj);
                                tempobj = nobj;
                            }
                            else
                            {
                                IDictionary <string, object> ndict;
                                if ((ndict = (obj as IDictionary <string, object>)) != null)
                                {
                                    Dictionary <string, object> nobj2 = new Dictionary <string, object>();
                                    ndict.Add(this.Name, nobj2);
                                    tempobj = nobj2;
                                }
                            }
                        }
                        else
                        {
                            if (obj is Array)
                            {
                                IList arr = obj as IList;
                                Dictionary <string, object> nobj3 = new Dictionary <string, object>();
                                tempobj         = nobj3;
                                arr[this.Index] = ReflectUtil.MatchType(nobj3, obj.GetType().GetElementType());
                            }
                            bool flag11 = this.Parent != null;
                            if (flag11)
                            {
                                IDictionary idict2;
                                if ((idict2 = (obj as IDictionary)) != null)
                                {
                                    Type otypee  = obj.GetType();
                                    Type gentype = otypee.GetGenericArguments().ElementAt(1);
                                    bool flag13  = gentype != typeof(object);
                                    if (flag13)
                                    {
                                        return;
                                    }
                                    Type   listType            = typeof(Dictionary <,>);
                                    Type   constructedListType = listType.MakeGenericType(otypee.GetGenericArguments());
                                    object nobj4 = Activator.CreateInstance(constructedListType);
                                    idict2.Add(this.Name, nobj4);
                                    tempobj = nobj4;
                                }
                                else
                                {
                                    IDictionary <string, object> ndict2;
                                    bool flag14 = (ndict2 = (obj as IDictionary <string, object>)) != null;
                                    if (flag14)
                                    {
                                        Dictionary <string, object> nobj5 = new Dictionary <string, object>();
                                        ndict2.Add(this.Name, nobj5);
                                        tempobj = nobj5;
                                    }
                                }
                            }
                        }
                        for (int i = 0; i < this.SubItems.Count; i++)
                        {
                            JsonItem item   = this.SubItems[i];
                            bool     flag15 = tempobj != null;
                            if (flag15)
                            {
                                item.ExportTo <object>(ref tempobj);
                            }
                            else
                            {
                                item.ExportTo <T>(ref obj);
                            }
                        }
                    }
                    else
                    {
                        bool flag16 = this.ObjectType == JsonItemType.OBJ_ARRAYITEM;
                        if (flag16)
                        {
                            IList list;
                            bool  flag17 = (list = (obj as IList)) != null;
                            if (flag17)
                            {
                                Type ntype         = list.GetType();
                                bool isGenericType = ntype.IsGenericType;
                                Type ltype;
                                if (isGenericType)
                                {
                                    ltype = ntype.GetGenericArguments().FirstOrDefault <Type>();
                                }
                                else
                                {
                                    ltype = list.GetType().GetElementType();
                                }
                                bool isFixedSize = list.IsFixedSize;
                                if (isFixedSize)
                                {
                                    list[this.Index] = ReflectUtil.MatchType(this.Value, ltype);
                                }
                                else
                                {
                                    list.Add(ReflectUtil.MatchType(this.Value, ltype));
                                }
                            }
                        }
                        else
                        {
                            if (this.ObjectType == JsonItemType.OBJ_VARIANT)
                            {
                                T           t     = obj;
                                Type        otype = t?.GetType();
                                IDictionary idict3;
                                bool        flag19 = (idict3 = (obj as IDictionary)) != null;
                                if (flag19)
                                {
                                    Type gentype2 = otype.GetGenericArguments().ElementAt(1);
                                    idict3.Add(this.Name, ReflectUtil.MatchType(this.Value, gentype2));
                                }
                                else
                                {
                                    IDictionary <string, object> sdict;
                                    if ((sdict = (obj as IDictionary <string, object>)) != null)
                                    {
                                        sdict.Add(this.Name, this.Value);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    bool flag21 = this.ObjectType != JsonItemType.OBJ_OBJECT;
                    if (!flag21)
                    {
                        Type         otype2  = obj.GetType();
                        MemberInfo[] members = otype2.GetMembers(BindingFlags.Instance | BindingFlags.Public);
                        foreach (MemberInfo member in members)
                        {
                            bool flag22 = member.MemberType != MemberTypes.Field && member.MemberType != MemberTypes.Property;
                            if (!flag22)
                            {
                                string        name = member.Name;
                                JsonAttribute jattribut;
                                if ((jattribut = (member.GetCustomAttribute(typeof(JsonAttribute)) as JsonAttribute)) != null)
                                {
                                    bool notMapped = jattribut.NotMapped;
                                    if (notMapped)
                                    {
                                        goto IL_7E6;
                                    }
                                    bool flag24 = !string.IsNullOrEmpty(jattribut.TagName);
                                    if (flag24)
                                    {
                                        name = jattribut.TagName;
                                    }
                                }
                                JsonItem item2  = this.Find(name);
                                bool     flag25 = item2 == null;
                                if (!flag25)
                                {
                                    FieldPropertyInfo fprop = new FieldPropertyInfo(member);
                                    bool flag26             = !fprop.CanWrite || !fprop.CanRead || fprop.HasIndexParameters();
                                    if (!flag26)
                                    {
                                        if (item2.ObjectType == JsonItemType.OBJ_OBJECT)
                                        {
                                            bool flag28 = !fprop.ObjectType.IsObject() && !fprop.ObjectType.IsDictionary();
                                            if (!flag28)
                                            {
                                                object curvalue = fprop.GetValue(obj);
                                                if (curvalue == null)
                                                {
                                                    if (fprop.ObjectType.IsDictionary())
                                                    {
                                                        Type listType2            = typeof(Dictionary <,>);
                                                        Type constructedListType2 = listType2.MakeGenericType(fprop.ObjectType.GetGenericArguments());
                                                        curvalue = Activator.CreateInstance(constructedListType2);
                                                        for (int j = 0; j < item2.SubItems.Count; j++)
                                                        {
                                                            item2.SubItems[j].ExportTo <object>(ref curvalue);
                                                        }
                                                        fprop.SetValue(obj, curvalue);
                                                        break;
                                                    }
                                                    curvalue = Activator.CreateInstance(fprop.ObjectType);
                                                }
                                                item2.ExportTo <object>(ref curvalue);
                                                fprop.SetValue(obj, curvalue);
                                            }
                                        }
                                        else
                                        {
                                            if (item2.ObjectType == JsonItemType.OBJ_ARRAY)
                                            {
                                                bool flag32 = !fprop.ObjectType.IsArray();
                                                if (!flag32)
                                                {
                                                    object curvalue2 = fprop.GetValue(obj);
                                                    if (curvalue2 == null)
                                                    {
                                                        Type listType3      = typeof(List <>);
                                                        bool isGenericType2 = fprop.ObjectType.IsGenericType;
                                                        if (isGenericType2)
                                                        {
                                                            Type constructedListType3 = listType3.MakeGenericType(fprop.ObjectType.GetGenericArguments());
                                                            curvalue2 = Activator.CreateInstance(constructedListType3);
                                                        }
                                                        else
                                                        {
                                                            Type elemtype = fprop.ObjectType.GetElementType();
                                                            if (elemtype != null)
                                                            {
                                                                curvalue2 = Array.CreateInstance(elemtype, item2.SubItems.Count);
                                                            }
                                                        }
                                                    }
                                                    item2.ExportTo <object>(ref curvalue2);
                                                    fprop.SetValue(obj, curvalue2);
                                                }
                                            }
                                            else
                                            {
                                                if (!fprop.ObjectType.IsObject() && !member.MemberType.IsArray())
                                                {
                                                    fprop.SetValue(obj, ReflectUtil.MatchType(item2.Value, fprop.ObjectType));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            IL_7E6 :;
                        }
                    }
                }
            }
        }
Example #16
0
      private string EncodeJson(JsonItem jsonItem)
      {
          string result2;

          if (jsonItem.ObjectType == JsonItemType.OBJ_SINGLE)
          {
              result2 = "\"" + jsonItem.Value + "\"";
          }
          else
          {
              if (jsonItem.ObjectType != JsonItemType.OBJ_ARRAY && jsonItem.ObjectType != JsonItemType.OBJ_OBJECT)
              {
                  result2 = null;
              }
              else
              {
                  StringBuilder sb    = new StringBuilder();
                  int           added = 0;
                  if (this.formattingtype != 0)
                  {
                      if (this.formattingtype == 2 || this.depth2 == 1)
                      {
                          if (!this.preventfirstlineformat)
                          {
                              sb.Append('\t', this.depth2);
                          }
                      }
                  }
                  this.preventfirstlineformat = false;
                  if (jsonItem.ObjectType == JsonItemType.OBJ_ARRAY)
                  {
                      sb.Append("[");
                  }
                  else
                  {
                      sb.Append("{");
                  }
                  if (this.formattingtype != 0)
                  {
                      if (this.formattingtype == 2 || this.depth2 == 0)
                      {
                          sb.Append("\r\n");
                      }
                  }
                  bool donotadd = false;
                  foreach (JsonItem jitem in jsonItem.SubItems)
                  {
                      bool flag9 = (jitem.ObjectType == JsonItemType.OBJ_COMMENT_SINGLELINE || jitem.ObjectType == JsonItemType.OBJ_COMMENT_MULTILINE) && !this.printComment;
                      if (!flag9)
                      {
                          bool flag10 = (jitem.ObjectType == JsonItemType.OBJ_COMMENT_SINGLELINE || jitem.ObjectType == JsonItemType.OBJ_COMMENT_MULTILINE) && this.formattingtype != 2;
                          if (!flag10)
                          {
                              if (added > 0)
                              {
                                  bool flag12 = !donotadd;
                                  if (flag12)
                                  {
                                      sb.Append(", ");
                                  }
                                  bool flag13 = donotadd;
                                  if (flag13)
                                  {
                                      donotadd = false;
                                  }
                                  if (this.formattingtype != 0)
                                  {
                                      if (this.formattingtype == 2 || this.depth2 == 0)
                                      {
                                          if (this.formattingtype == 2)
                                          {
                                              if (jitem.ObjectType == JsonItemType.OBJ_COMMENT_SINGLELINE || jitem.ObjectType == JsonItemType.OBJ_COMMENT_MULTILINE || added == 0)
                                              {
                                                  if (jitem.LineOffset > 0)
                                                  {
                                                      for (int i = 0; i < jitem.LineOffset; i++)
                                                      {
                                                          sb.Append("\r\n");
                                                      }
                                                  }
                                                  else
                                                  {
                                                      sb.Append(" ");
                                                  }
                                              }
                                              else
                                              {
                                                  sb.Append("\r\n");
                                              }
                                          }
                                          else
                                          {
                                              sb.Append("\r\n");
                                          }
                                      }
                                  }
                              }
                              if (jsonItem.ObjectType == JsonItemType.OBJ_ARRAY)
                              {
                                  if (jsonItem.ObjectType == JsonItemType.OBJ_NONE || jsonItem.ObjectType == JsonItemType.OBJ_SINGLE || jsonItem.ObjectType == JsonItemType.OBJ_VARIANT)
                                  {
                                      return(null);
                                  }
                              }
                              else
                              {
                                  if (jsonItem.ObjectType == JsonItemType.OBJ_NONE || jsonItem.ObjectType == JsonItemType.OBJ_SINGLE || jsonItem.ObjectType == JsonItemType.OBJ_ARRAYITEM)
                                  {
                                      return(null);
                                  }
                              }
                              if (jitem.ObjectType == JsonItemType.OBJ_ARRAY || jitem.ObjectType == JsonItemType.OBJ_OBJECT)
                              {
                                  this.depth2++;
                                  if (jsonItem.ObjectType == JsonItemType.OBJ_OBJECT)
                                  {
                                      this.preventfirstlineformat = true;
                                  }
                                  string result = this.EncodeJson(jitem);
                                  if (result == null)
                                  {
                                      return(null);
                                  }
                                  if (jsonItem.ObjectType == JsonItemType.OBJ_ARRAY)
                                  {
                                      sb.Append(result);
                                  }
                                  else
                                  {
                                      if (this.formattingtype != 0)
                                      {
                                          if (this.formattingtype == 2 || this.depth2 == 1)
                                          {
                                              sb.Append('\t', this.depth2);
                                          }
                                      }
                                      bool   isParse = this.rootItem.IsParse;
                                      string name;
                                      if (isParse)
                                      {
                                          if (jitem.NameQuot > '\0')
                                          {
                                              name = jitem.NameQuot.ToString() + jitem.Name + jitem.NameQuot.ToString();
                                          }
                                          else
                                          {
                                              name = jitem.Name;
                                          }
                                      }
                                      else
                                      {
                                          name = "\"" + jitem.Name + "\"";
                                      }
                                      sb.Append(name + ": ");
                                      sb.Append(result);
                                  }
                                  added++;
                                  this.depth2--;
                              }
                              else
                              {
                                  if (this.formattingtype != 0)
                                  {
                                      if (this.formattingtype == 2 || this.depth2 == 0)
                                      {
                                          if (jitem.ObjectType == JsonItemType.OBJ_COMMENT_SINGLELINE || jitem.ObjectType == JsonItemType.OBJ_COMMENT_MULTILINE)
                                          {
                                              if (jitem.LineOffset > 0 || added == 0)
                                              {
                                                  sb.Append('\t', this.depth2 + 1);
                                              }
                                          }
                                          else
                                          {
                                              sb.Append('\t', this.depth2 + 1);
                                          }
                                      }
                                  }
                                  if (jitem.ObjectType == JsonItemType.OBJ_COMMENT_SINGLELINE || jitem.ObjectType == JsonItemType.OBJ_COMMENT_MULTILINE)
                                  {
                                      if (jitem.ObjectType == JsonItemType.OBJ_COMMENT_SINGLELINE)
                                      {
                                          sb.Append("//");
                                          sb.Append(jitem.Value);
                                      }
                                      else
                                      {
                                          sb.Append("/*");
                                          sb.Append(jitem.Value);
                                          sb.Append("*/");
                                      }
                                      donotadd = true;
                                  }
                                  else
                                  {
                                      if (jsonItem.ObjectType == JsonItemType.OBJ_ARRAY)
                                      {
                                          string value;
                                          if (this.rootItem.IsParse || !(jitem.Value is string))
                                          {
                                              if (jitem.Value == null)
                                              {
                                                  value = "null";
                                              }
                                              else
                                              {
                                                  if (jitem.Value is bool)
                                                  {
                                                      value = jitem.Value.ToString().ToLower();
                                                  }
                                                  else
                                                  {
                                                      if (jitem.ValueQuot > '\0')
                                                      {
                                                          value = jitem.ValueQuot.ToString() + jitem.GetValueWithVars() + jitem.ValueQuot.ToString();
                                                      }
                                                      else
                                                      {
                                                          value = jitem.GetValueWithVars();
                                                      }
                                                  }
                                              }
                                          }
                                          else
                                          {
                                              value = "\"" + jitem.GetValueWithVars() + "\"";
                                          }
                                          sb.Append(value);
                                      }
                                      else
                                      {
                                          string name2;
                                          string value2;
                                          if (this.rootItem.IsParse || !(jitem.Value is string))
                                          {
                                              if (jitem.NameQuot > '\0')
                                              {
                                                  name2 = jitem.NameQuot.ToString() + jitem.Name + jitem.NameQuot.ToString();
                                              }
                                              else
                                              {
                                                  name2 = jitem.Name;
                                              }
                                              if (jitem.Value == null)
                                              {
                                                  value2 = "null";
                                              }
                                              else
                                              {
                                                  if (jitem.Value is bool)
                                                  {
                                                      value2 = jitem.Value.ToString().ToLower();
                                                  }
                                                  else
                                                  {
                                                      bool flag44 = jitem.ValueQuot > '\0';
                                                      if (flag44)
                                                      {
                                                          value2 = jitem.ValueQuot.ToString() + jitem.GetValueWithVars() + jitem.ValueQuot.ToString();
                                                      }
                                                      else
                                                      {
                                                          value2 = jitem.GetValueWithVars();
                                                      }
                                                  }
                                              }
                                          }
                                          else
                                          {
                                              name2  = "\"" + jitem.Name + "\"";
                                              value2 = "\"" + jitem.GetValueWithVars() + "\"";
                                          }
                                          sb.Append(name2 + ": " + value2);
                                      }
                                  }
                                  added++;
                              }
                          }
                      }
                  }
                  if (this.formattingtype != 0)
                  {
                      if (this.formattingtype == 2 || this.depth2 == 0)
                      {
                          sb.Append("\r\n");
                          bool flag47 = this.formattingtype == 2;
                          if (flag47)
                          {
                              sb.Append('\t', this.depth2);
                          }
                      }
                  }
                  if (jsonItem.ObjectType == JsonItemType.OBJ_ARRAY)
                  {
                      sb.Append("]");
                  }
                  else
                  {
                      sb.Append("}");
                  }
                  result2 = sb.ToString();
              }
          }
          return(result2);
      }