예제 #1
0
        /// <summary>
        /// Attempts to find a TNumber value for the TType given. If there is no error, but the TNumber reference
        /// given is still null after calling, then the TType is a TString (i.e. some arithmetic will work (+)).
        /// </summary>
        /// <param name="interpreter">The interpreter that the method is being called from.</param>
        /// <param name="number">The TNumber reference to assign the result to.</param>
        /// <param name="value">The TType to get a TNumber out of.</param>
        /// <returns>An exception if there was an error, otherwise null.</returns>
        private static TException AssignNumberValue(Interpreter interpreter, out TNumber number, TType value)
        {
            // Attempt to cast the TType 'value' argument to a TNumber. Failing that, check if it's a TString.
            // If the value is a TNumber or a TString, return null (i.e. no exception). If it's a TVariable then
            // work on the value of the TVariable, otherwise return an exception.


            number = value as TNumber;
            if ((number != null) || (value is TString))
            {
                return(null);
            }

            TVariable variable = value as TVariable;

            if (variable != null)
            {
                value  = variable.Value;
                number = value as TNumber;
                if ((number != null) || (value is TString))
                {
                    return(null);
                }
                return(new TException(interpreter, "Value of '" + variable.Identifier + "' is not a number",
                                      "it is of type '" + value.TypeName + "'"));
            }

            return(new TException(interpreter, "'" + value.ToCSString() + "' is not a number",
                                  "it is of type '" + value.TypeName + "'"));
        }