Пример #1
0
            object ParseNext(Type type)
            {
                switch (NextToken)
                {
                case TOKEN.STRING:
                    return(ParseString(type));

                case TOKEN.NUMBER:
                    return(ParseNumber(type));

                case TOKEN.CURLY_OPEN:
                    if (type_rts_list_interface.IsAssignableFrom(type))
                    {
                        IRTSList list = Activator.CreateInstance(type) as IRTSList;
                        ParseObjectArray(list, type.GetGenericArguments()[0]);
                        return(list);
                    }
                    if (type_rts_dict_interface.IsAssignableFrom(type))
                    {
                        IRTSDict dict = Activator.CreateInstance(type) as IRTSDict;
                        ParseObjectDict(dict, type.GetGenericArguments()[0]);
                        return(dict);
                    }
                    else
                    {
                        return(ParseObject(type));
                    }

                case TOKEN.SQUARED_OPEN:
                    IRTSList array = type != null?Activator.CreateInstance(type) as IRTSList : null;

                    ParseObjectArray(array, type);
                    return(array);

                case TOKEN.TRUE:
                    return(true);

                case TOKEN.FALSE:
                    return(false);

                case TOKEN.NULL:
                    return(null);

                default:
                    return(null);
                }
            }
Пример #2
0
        private void OnDictItemModify(IRTSDict dict, string k)
        {
            int index = IndexOf((T)dict);

            if (index < 0)
            {
                return;
            }
            Entry entry = entries[index];

            if (entry.s <= 0)
            {
                entry.s        = (byte)(k == null ? 2 : 1);
                entries[index] = entry;
            }
            onModify?.Invoke(this, entry.key);
        }
Пример #3
0
        private void OnDictItemModify(IRTSDict dict, string k)
        {
            int index = IndexOf((T)dict);

            if (index < 0)
            {
                return;
            }
            Node n = _items[index];

            if (n.s <= 0)
            {
                n.s           = (byte)(k == null ? 2 : 1);
                _items[index] = n;
            }
            _items[index] = n;
            onModify?.Invoke(this, index);
        }
Пример #4
0
        private void TryClearHandlers(object item)
        {
            DataNodeBase node = item as DataNodeBase;

            if (node != null)
            {
                node.onModify = null; return;
            }
            IRTSList list = item as IRTSList;

            if (list != null)
            {
                list.onModify = null; return;
            }
            IRTSDict dict = item as IRTSDict;

            if (dict != null)
            {
                dict.onModify = null; return;
            }
        }
Пример #5
0
        private void TryRegisterHandler(object item)
        {
            DataNodeBase node = item as DataNodeBase;

            if (node != null)
            {
                node.onModify = mOnItemModify;
                return;
            }
            IRTSList list = item as IRTSList;

            if (list != null)
            {
                list.onModify = mOnListItemModify;
                return;
            }
            IRTSDict dict = item as IRTSDict;

            if (dict != null)
            {
                dict.onModify = mOnDictItemModify;
            }
        }
Пример #6
0
            bool ParseObjectDict(IRTSDict dict, Type type)
            {
                if (NextToken != TOKEN.CURLY_OPEN)
                {
                    return(false);
                }
                json.Read();
                while (true)
                {
                    switch (NextToken)
                    {
                    case TOKEN.NONE:
                        return(false);

                    case TOKEN.COMMA:
                        continue;

                    case TOKEN.CURLY_CLOSE:
                        return(true);
                    }
                    string name = ParseString(type_string);
                    if (name == null)
                    {
                        return(false);
                    }
                    if (NextToken != TOKEN.COLON)
                    {
                        return(false);
                    }
                    json.Read();
                    object value = ParseNext(type);
                    if (dict != null && name != "[]")
                    {
                        dict.Add(name, value);
                    }
                }
            }
Пример #7
0
            void SerializeDict(IRTSDict dict, bool list2dict, bool perfectPrint)
            {
                if (perfectPrint)
                {
                    builder.Append(indent);
                }
                builder.Append("{");
                indent = indent + "    ";
                int i = 0;
                IDictionaryEnumerator iter = dict.GetEnumerator();

                while (iter.MoveNext())
                {
                    if (i > 0)
                    {
                        builder.Append(',');
                    }
                    if (perfectPrint)
                    {
                        builder.AppendLine();
                        builder.Append(indent);
                    }
                    builder.Append("\"");
                    builder.Append(iter.Key.ToString());
                    builder.Append("\":");
                    SerializeValue(false, iter.Value, list2dict, perfectPrint);
                    i++;
                }
                indent = indent.Substring(4);
                if (perfectPrint)
                {
                    builder.AppendLine();
                    builder.Append(indent);
                }
                builder.Append("}");
            }