Пример #1
0
        public void Set <T>(string Key, T Value)
        {
            if (StringExtensions.Contains(Key, '.'))
            {
                jsObject Current = this;
                int      Open = 0, Close = Key.Find('.');

                while (Current != null && Open != -1 && Close != -1)
                {
                    var Sub = Key.Substring(Open, Close - Open);

                    if (Close == Key.Length)
                    {
                        if (Value == null)
                        {
                            Current.Remove(Sub);
                        }
                        else
                        {
                            Current.AssignValue <T>(Sub, Value);
                        }
                        return;
                    }

                    var Next = Current.SearchForItem <jsObject>(Sub);

                    if (Next == null)
                    {
                        Next = new jsObject();
                        Current.AssignValue(Sub, Next);
                    }
                    Current = Next;

                    Open  = Close + 1;
                    Close = Key.Find('.', Open);

                    if (Close == -1)
                    {
                        Close = Key.Length;
                    }
                }
            }

            if (Value == null)
            {
                this.Remove(Key);
            }
            else
            {
                this.AssignValue(Key, Value);
            }
        }
Пример #2
0
        public T Get <T>(string[] Keys)
        {
            jsObject Current = this;

            for (int i = 0; Current != null && i < Keys.Length; i++)
            {
                var Sub = Keys[i];

                if (StringExtensions.Contains(Sub, '.'))
                {
                    Current = Current.Get <jsObject>(Sub);
                    continue;
                }

                if ((Keys.Length - i) == 1)
                {
                    return(Current.SearchForItem <T>(Sub));
                }

                Current = Current.SearchForItem <jsObject>(Sub);
            }
            return(default(T));
        }
Пример #3
0
        public T Get <T>(string Key)
        {
            if (StringExtensions.Contains(Key, '.'))
            {
                int      Open = 0, Close = Key.Find('.');
                jsObject Current = this;

                while (Current != null && Open != -1 && Close != -1)
                {
                    var Sub = Key.Substring(Open, Close - Open);

                    if (Close == Key.Length)
                    {
                        return(Current.SearchForItem <T>(Sub));
                    }

                    var Next = Current.SearchForItem <jsObject>(Sub);

                    if (Next == null)
                    {
                        return(default(T));
                    }
                    Current = Next;


                    Open  = Close + 1;
                    Close = Key.Find('.', Open);

                    if (Close == -1)
                    {
                        Close = Key.Length;
                    }
                }
            }

            return(SearchForItem <T>(Key));
        }