예제 #1
0
        private void ParseConstructor()
        {
            if (MatchValue("new", true))
            {
                if (EatWhitespace(true))
                {
                    while (char.IsLetter(_currentChar))
                    {
                        _buffer.Append(_currentChar);
                        MoveNext();
                    }

                    string constructorName = _buffer.ToString();
                    _buffer.Position = 0;

                    ArrayList parameters = new ArrayList();

                    EatWhitespace(false);

                    if (_currentChar == '(' && MoveNext())
                    {
                        _currentState = State.Constructor;

                        while (ParseValue())
                        {
                            parameters.Add(_value);
                            _currentState = State.Constructor;
                        }

                        if (string.CompareOrdinal(constructorName, "Date") == 0)
                        {
                            long javaScriptTicks = Convert.ToInt64(parameters[0]);

                            DateTime date = JavaScriptConvert.ConvertJavaScriptTicksToDateTime(javaScriptTicks);

                            SetToken(JsonToken.Date, date);
                        }
                        else
                        {
                            JavaScriptConstructor constructor = new JavaScriptConstructor(constructorName, new JavaScriptParameters(parameters));

                            if (_currentState == State.ConstructorEnd)
                            {
                                SetToken(JsonToken.Constructor, constructor);
                            }
                        }

                        // move past ')'
                        MoveNext();
                    }
                }
            }
        }
예제 #2
0
 private void ParseConstructor()
 {
     if (this.MatchValue("new", true) && this.EatWhitespace(true))
     {
         while (char.IsLetter(this._currentChar))
         {
             this._buffer.Append(this._currentChar);
             this.MoveNext();
         }
         string strA = this._buffer.ToString();
         this._buffer.Position = 0;
         ArrayList list = new ArrayList();
         this.EatWhitespace(false);
         if ((this._currentChar == '(') && this.MoveNext())
         {
             this._currentState = State.Constructor;
             while (this.ParseValue())
             {
                 list.Add(this._value);
                 this._currentState = State.Constructor;
             }
             if (string.CompareOrdinal(strA, "Date") == 0)
             {
                 DateTime time = JavaScriptConvert.ConvertJavaScriptTicksToDateTime(Convert.ToInt64(list[0]));
                 this.SetToken(JsonToken.Date, time);
             }
             else
             {
                 JavaScriptConstructor constructor = new JavaScriptConstructor(strA, new JavaScriptParameters(list));
                 if (this._currentState == State.ConstructorEnd)
                 {
                     this.SetToken(JsonToken.Constructor, constructor);
                 }
             }
             this.MoveNext();
         }
     }
 }
예제 #3
0
		private void ParseConstructor()
		{
			if (MatchValue("new", true))
			{
				if (EatWhitespace(true))
				{
					while (char.IsLetter(_currentChar))
					{
						_buffer.Append(_currentChar);
						MoveNext();
					}

					string constructorName = _buffer.ToString();
					_buffer.Position = 0;

					ArrayList parameters = new ArrayList();

					EatWhitespace(false);

					if (_currentChar == '(' && MoveNext())
					{
						_currentState = State.Constructor;

						while (ParseValue())
						{
							parameters.Add(_value);
							_currentState = State.Constructor;
						}

						if (string.CompareOrdinal(constructorName, "Date") == 0)
						{
							long javaScriptTicks = Convert.ToInt64(parameters[0]);

							DateTime date = JavaScriptConvert.ConvertJavaScriptTicksToDateTime(javaScriptTicks);

							SetToken(JsonToken.Date, date);
						}
						else
						{
							JavaScriptConstructor constructor = new JavaScriptConstructor(constructorName, new JavaScriptParameters(parameters));

							if (_currentState == State.ConstructorEnd)
							{
								SetToken(JsonToken.Constructor, constructor);
							}
						}

						// move past ')'
						MoveNext();
					}
				}
			}
		}