Exemple #1
0
        //---------------------------------------------------------------------

        public InputVariableException(InputVariable var,
                                      string message,
                                      Exception exception)
            : base(message, exception)
        {
            Variable = var;
        }
        //---------------------------------------------------------------------

        private bool ReadVariable(InputVariable var,
                                  bool optional)
        {
            if (var == null)
            {
                throw new System.ArgumentNullException();
            }
            if (VariableNameMatches(var.Name, optional))
            {
                //  Read the variable's value
                StringReader strReader = new StringReader(textAfterName);
                try {
                    var.ReadValue(strReader);
                }
                catch (InputVariableException exc) {
                    throw new LineReaderException(reader, exc);
                }
                TextReader.SkipWhitespace(strReader);
                string textAfterValue = strReader.ReadToEnd();
                if (textAfterValue.Length == 0)
                {
                    return(true);
                }
                string message = string.Format("Extra text after the value for \"{0}\"",
                                               var.Name);
                throw ExtraTextException(message, textAfterValue);
            }
            return(false);
        }
Exemple #3
0
        //---------------------------------------------------------------------

        public InputVariableException(InputVariable var,
                                      string message,
                                      params object[] args)
            : base(string.Format(message, args))
        {
            Variable = var;
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Reads the name and value of an input variable from the current
        /// line.
        /// </summary>
        /// <exception cref="LineReaderException">
        /// </exception>
        /// <remarks>
        /// After a call to this method, the property CurrentLine will refer
        /// to the next data line after the line with the variable that was
        /// just read.  The caller can perform additional error-checking on
        /// the variable's value after this method returns.  If the caller
        /// detects an error, it should throw an InputValueException or
        /// an InputVariableException.
        /// </remarks>
        protected void ReadVar(InputVariable var)
        {
            Debug.Assert(inputLine != null);
            inputLine.ReadVar(var);
            SetCurrentVar(var);
            GetNextLine();
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Reads the value of an input variable from the current line.
        /// </summary>
        /// <exception cref="InputValueException">
        /// </exception>
        /// <remarks>
        /// This method is used for reading column values from a table.  The
        /// current line is a row in the table.
        /// </remarks>
        protected void ReadValue(InputVariable var,
                                 StringReader currentLine)
        {
            Require.ArgumentNotNull(var);
            Require.ArgumentNotNull(currentLine);
            var.ReadValue(currentLine);
            SetCurrentVar(var);
        }
        //---------------------------------------------------------------------

        private void SetCurrentVar(InputVariable var)
        {
            currentVar = var;
            if (inputLine != null)
            {
                currentVarLineNum = inputLine.Number;
            }
            else
            {
                currentVarLineNum = 0;
            }
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Reads the name and value of an optional input variable from the
        /// current line.
        /// </summary>
        /// <returns>
        /// true if the name and value were read; false if the name on the
        /// current line does not match the variable's name.
        /// </returns>
        /// <exception cref="LineReaderException">
        /// </exception>
        /// <remarks>
        /// If this method return true, the property CurrentLine will refer
        /// to the next data line after the line with the variable that was
        /// just read.  The caller can perform additional error-checking on
        /// the variable's value after this method returns.  If the caller
        /// detects an error, it should throw an InputValueException or
        /// an InputVariableException.
        /// </remarks>
        protected bool ReadOptionalVar(InputVariable var)
        {
            Debug.Assert(inputLine != null);
            if (inputLine.ReadOptionalVar(var))
            {
                SetCurrentVar(var);
                GetNextLine();
                return(true);
            }
            else
            {
                return(false);
            }
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Reads the name and value for an optional InputVariable.
        /// </summary>
        public bool ReadOptionalVar(InputVariable var)
        {
            return(ReadVariable(var, true));
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Reads the name and value for an InputVariable.
        /// </summary>
        public void ReadVar(InputVariable var)
        {
            ReadVariable(var, false);
        }