Exemple #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;

                    List <object> parameters = new List <object>();

                    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]);

                            System.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();
                    }
                }
            }
        }
Exemple #2
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;

              List<object> parameters = new List<object>();

              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]);

              System.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();
              }
            }
              }
        }