Exemple #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);
                }
            }
Exemple #2
0
        private void OnListItemModify(IRTSList list, int i)
        {
            int index = IndexOf((T)list);

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

            if (entry.s <= 0)
            {
                entry.s        = (byte)(i < 0 ? 2 : 1);
                entries[index] = entry;
            }
            onModify?.Invoke(this, entry.key);
        }
Exemple #3
0
        private void OnListItemModify(IRTSList list, int i)
        {
            int index = IndexOf((T)list);

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

            if (n.s <= 0)
            {
                n.s           = (byte)(i < 0 ? 2 : 1);
                _items[index] = n;
            }
            _items[index] = n;
            onModify?.Invoke(this, index);
        }
Exemple #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;
            }
        }
Exemple #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;
            }
        }
Exemple #6
0
 void SerializeArray(IRTSList anArray, bool list2dict, bool perfectPrint)
 {
     if (list2dict)
     {
         if (perfectPrint)
         {
             builder.Append(indent);
         }
         builder.Append("{");
         indent = indent + "    ";
         int i = 0;
         foreach (object obj in anArray)
         {
             if (i > 0)
             {
                 builder.Append(',');
             }
             if (perfectPrint)
             {
                 builder.AppendLine();
                 builder.Append(indent);
             }
             builder.Append("\"");
             builder.Append(RTSListUtil.ToKey(anArray.GetPriority(i)));
             builder.Append("\":");
             SerializeValue(false, obj, list2dict, perfectPrint);
             i++;
         }
         indent = indent.Substring(4);
         if (perfectPrint)
         {
             builder.AppendLine();
             builder.Append(indent);
         }
         builder.Append("}");
     }
     else
     {
         if (perfectPrint)
         {
             builder.Append(indent);
         }
         builder.Append('[');
         indent = indent + "    ";
         bool first = true;
         foreach (object obj in anArray)
         {
             if (!first)
             {
                 builder.Append(',');
             }
             if (perfectPrint)
             {
                 builder.AppendLine();
                 builder.Append(indent);
             }
             SerializeValue(false, obj, list2dict, perfectPrint);
             first = false;
         }
         indent = indent.Substring(4);
         if (perfectPrint)
         {
             builder.AppendLine();
             builder.Append(indent);
         }
         builder.Append(']');
     }
 }
Exemple #7
0
            bool ParseObjectArray(IRTSList array, Type type)
            {
                switch (NextToken)
                {
                case TOKEN.CURLY_OPEN:
                    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 (!double.IsNaN(RTSListUtil.FromKey(name)))
                        {
                            double p = double.Parse(name.Substring(1, name.Length - 1));
                            if (array != null)
                            {
                                array.RawAdd(p, value);
                            }
                        }
                        else
                        {
                            if (array != null)
                            {
                                array.Add(value);
                            }
                        }
                    }

                case TOKEN.SQUARED_OPEN:
                    json.Read();
                    while (true)
                    {
                        switch (NextToken)
                        {
                        case TOKEN.NONE:
                            return(false);

                        case TOKEN.COMMA:
                            continue;

                        case TOKEN.SQUARED_CLOSE:
                            return(true);

                        default:
                            object value = ParseNext(type);
                            if (array != null)
                            {
                                array.Add(value);
                            }
                            break;
                        }
                    }
                }
                return(false);
            }