Esempio n. 1
0
 public void SinglePropertyAndIndexer()
 {
   JPath path = new JPath("Blah[0]");
   Assert.AreEqual(2, path.Parts.Count);
   Assert.AreEqual("Blah", path.Parts[0]);
   Assert.AreEqual(0, path.Parts[1]);
 }
Esempio n. 2
0
 public void TwoProperties()
 {
   JPath path = new JPath("Blah.Two");
   Assert.AreEqual(2, path.Parts.Count);
   Assert.AreEqual("Blah", path.Parts[0]);
   Assert.AreEqual("Two", path.Parts[1]);
 }
Esempio n. 3
0
 public void MultiplePropertiesAndIndexers()
 {
   JPath path = new JPath("Blah[0].Two.Three[1].Four");
   Assert.AreEqual(6, path.Parts.Count);
   Assert.AreEqual("Blah", path.Parts[0]);
   Assert.AreEqual(0, path.Parts[1]);
   Assert.AreEqual("Two", path.Parts[2]);
   Assert.AreEqual("Three", path.Parts[3]);
   Assert.AreEqual(1, path.Parts[4]);
   Assert.AreEqual("Four", path.Parts[5]);
 }
 public void AdditionalDots()
 {
   JPath path = new JPath(".Blah..[0]..Two.Three....[1].Four.");
   Assert.AreEqual(6, path.Parts.Count);
   Assert.AreEqual("Blah", path.Parts[0]);
   Assert.AreEqual(0, path.Parts[1]);
   Assert.AreEqual("Two", path.Parts[2]);
   Assert.AreEqual("Three", path.Parts[3]);
   Assert.AreEqual(1, path.Parts[4]);
   Assert.AreEqual("Four", path.Parts[5]);
 }
Esempio n. 5
0
 public void SingleProperty()
 {
   JPath path = new JPath("Blah");
   Assert.AreEqual(1, path.Parts.Count);
   Assert.AreEqual("Blah", path.Parts[0]);
 }
Esempio n. 6
0
 public void AdjacentIndexers()
 {
   JPath path = new JPath("[1][0][0][" + int.MaxValue + "]");
   Assert.AreEqual(4, path.Parts.Count);
   Assert.AreEqual(1, path.Parts[0]);
   Assert.AreEqual(0, path.Parts[1]);
   Assert.AreEqual(0, path.Parts[2]);
   Assert.AreEqual(int.MaxValue, path.Parts[3]);
 }
Esempio n. 7
0
 public void IndexerOnly()
 {
   JPath path = new JPath("[111119990]");
   Assert.AreEqual(1, path.Parts.Count);
   Assert.AreEqual(111119990, path.Parts[0]);
 }
Esempio n. 8
0
        public JToken SelectToken(string path, bool errorWhenNoMatch)
        {
            JPath jPath = new JPath(path);

            return(jPath.Evaluate(this, errorWhenNoMatch));
        }
Esempio n. 9
0
        private void ParseMain()
        {
            char chr;
            int  num  = this._currentIndex;
            bool flag = false;

            while (true)
            {
                if (this._currentIndex >= this._expression.Length)
                {
                    if (this._currentIndex > num)
                    {
                        string str = this._expression.Substring(num, this._currentIndex - num);
                        this.Parts.Add(str);
                    }
                    return;
                }
                chr = this._expression[this._currentIndex];
                if (chr != '(')
                {
                    if (chr == ')')
                    {
                        break;
                    }
                    switch (chr)
                    {
                    case '[':
                    {
                        break;
                    }

                    case ']':
                    {
                        throw new Exception(string.Concat("Unexpected character while parsing path: ", chr));
                    }

                    default:
                    {
                        if (chr == '.')
                        {
                            if (this._currentIndex > num)
                            {
                                string str1 = this._expression.Substring(num, this._currentIndex - num);
                                this.Parts.Add(str1);
                            }
                            num  = this._currentIndex + 1;
                            flag = false;
                            goto Label1;
                        }
                        else
                        {
                            if (flag)
                            {
                                throw new Exception(string.Concat("Unexpected character following indexer: ", chr));
                            }
                            goto Label1;
                        }
                    }
                    }
                }
                if (this._currentIndex > num)
                {
                    string str2 = this._expression.Substring(num, this._currentIndex - num);
                    this.Parts.Add(str2);
                }
                this.ParseIndexer(chr);
                num  = this._currentIndex + 1;
                flag = true;
Label1:
                JPath jPath = this;
                jPath._currentIndex++;
            }
            throw new Exception(string.Concat("Unexpected character while parsing path: ", chr));
        }