ArgumentType() public static method

public static ArgumentType ( string function, int arg, Type type ) : Exception
function string
arg int
type System.Type
return System.Exception
Ejemplo n.º 1
0
        private Type GetDataType(ExpressionNode node)
        {
            Type   nodeType = node.GetType();
            string typeName = null;

            if (nodeType == typeof(NameNode))
            {
                typeName = ((NameNode)node)._name;
            }
            if (nodeType == typeof(ConstNode))
            {
                typeName = ((ConstNode)node)._val.ToString();
            }

            if (typeName == null)
            {
                throw ExprException.ArgumentType(s_funcs[_info]._name, 2, typeof(Type));
            }

            Type dataType = Type.GetType(typeName);

            if (dataType == null)
            {
                throw ExprException.InvalidType(typeName);
            }

            // ReadXml might not be on the current call stack. So we'll use the TypeLimiter
            // that was captured when this FunctionNode instance was created.

            TypeLimiter.EnsureTypeIsAllowed(dataType, _capturedLimiter);

            return(dataType);
        }
Ejemplo n.º 2
0
        private Type GetDataType(ExpressionNode node)
        {
            Type   nodeType = node.GetType();
            string typeName = null;

            if (nodeType == typeof(NameNode))
            {
                typeName = ((NameNode)node)._name;
            }
            if (nodeType == typeof(ConstNode))
            {
                typeName = ((ConstNode)node)._val.ToString();
            }

            if (typeName == null)
            {
                throw ExprException.ArgumentType(s_funcs[_info]._name, 2, typeof(Type));
            }

            Type dataType = Type.GetType(typeName);

            if (dataType == null)
            {
                throw ExprException.InvalidType(typeName);
            }

            return(dataType);
        }
Ejemplo n.º 3
0
        internal override object Eval(DataRow row, DataRowVersion version)
        {
            Debug.Assert(_info < s_funcs.Length && _info >= 0, "Invalid function info.");

            object[] argumentValues = new object[_argumentCount];

            Debug.Assert(_argumentCount == s_funcs[_info]._argumentCount || s_funcs[_info]._isVariantArgumentList, "Invalid argument argumentCount.");

            // special case of the Convert function
            if (s_funcs[_info]._id == FunctionId.Convert)
            {
                if (_argumentCount != 2)
                {
                    throw ExprException.FunctionArgumentCount(_name);
                }

                argumentValues[0] = _arguments[0].Eval(row, version);
                argumentValues[1] = GetDataType(_arguments[1]);
            }
            else if (s_funcs[_info]._id != FunctionId.Iif)
            { // We do not want to evaluate arguments of IIF, we will already do it in EvalFunction/ second point: we may go to div by 0
                for (int i = 0; i < _argumentCount; i++)
                {
                    argumentValues[i] = _arguments[i].Eval(row, version);

                    if (s_funcs[_info]._isValidateArguments)
                    {
                        if ((argumentValues[i] == DBNull.Value) || (typeof(object) == s_funcs[_info]._parameters[i]))
                        {
                            // currently all supported functions with IsValidateArguments set to true
                            // NOTE: for IIF and ISNULL IsValidateArguments set to false
                            return(DBNull.Value);
                        }

                        if (argumentValues[i].GetType() != s_funcs[_info]._parameters[i])
                        {
                            // We are allowing conversions in one very specific case: int, int64,...'nice' numeric to numeric..

                            if (s_funcs[_info]._parameters[i] == typeof(int) && ExpressionNode.IsInteger(DataStorage.GetStorageType(argumentValues[i].GetType())))
                            {
                                argumentValues[i] = Convert.ToInt32(argumentValues[i], FormatProvider);
                            }
                            else if ((s_funcs[_info]._id == FunctionId.Trim) || (s_funcs[_info]._id == FunctionId.Substring) || (s_funcs[_info]._id == FunctionId.Len))
                            {
                                if ((typeof(string) != (argumentValues[i].GetType())) && (typeof(SqlString) != (argumentValues[i].GetType())))
                                {
                                    throw ExprException.ArgumentType(s_funcs[_info]._name, i + 1, s_funcs[_info]._parameters[i]);
                                }
                            }
                            else
                            {
                                throw ExprException.ArgumentType(s_funcs[_info]._name, i + 1, s_funcs[_info]._parameters[i]);
                            }
                        }
                    }
                }
            }
            return(EvalFunction(s_funcs[_info]._id, argumentValues, row, version));
        }
Ejemplo n.º 4
0
 internal override object Eval(DataRow row, DataRowVersion version)
 {
     object[] argumentValues = new object[this.argumentCount];
     if (funcs[this.info].id == FunctionId.Convert)
     {
         if (this.argumentCount != 2)
         {
             throw ExprException.FunctionArgumentCount(this.name);
         }
         argumentValues[0] = this.arguments[0].Eval(row, version);
         argumentValues[1] = this.GetDataType(this.arguments[1]);
     }
     else if (funcs[this.info].id != FunctionId.Iif)
     {
         for (int i = 0; i < this.argumentCount; i++)
         {
             argumentValues[i] = this.arguments[i].Eval(row, version);
             if (funcs[this.info].IsValidateArguments)
             {
                 if ((argumentValues[i] == DBNull.Value) || (typeof(object) == funcs[this.info].parameters[i]))
                 {
                     return(DBNull.Value);
                 }
                 if (argumentValues[i].GetType() != funcs[this.info].parameters[i])
                 {
                     if ((funcs[this.info].parameters[i] == typeof(int)) && ExpressionNode.IsInteger(DataStorage.GetStorageType(argumentValues[i].GetType())))
                     {
                         argumentValues[i] = Convert.ToInt32(argumentValues[i], base.FormatProvider);
                     }
                     else
                     {
                         if (((funcs[this.info].id != FunctionId.Trim) && (funcs[this.info].id != FunctionId.Substring)) && (funcs[this.info].id != FunctionId.Len))
                         {
                             throw ExprException.ArgumentType(funcs[this.info].name, i + 1, funcs[this.info].parameters[i]);
                         }
                         if ((typeof(string) != argumentValues[i].GetType()) && (typeof(SqlString) != argumentValues[i].GetType()))
                         {
                             throw ExprException.ArgumentType(funcs[this.info].name, i + 1, funcs[this.info].parameters[i]);
                         }
                     }
                 }
             }
         }
     }
     return(this.EvalFunction(funcs[this.info].id, argumentValues, row, version));
 }
Ejemplo n.º 5
0
        internal override object Eval(DataRow row, DataRowVersion version)
        {
            Debug.Assert(info < funcs.Length && info >= 0, "Invalid function info.");

            object[] argumentValues = new object[this.argumentCount];

            Debug.Assert(this.argumentCount == funcs[info].argumentCount || funcs[info].IsVariantArgumentList, "Invalid argument argumentCount.");

            // special case of the Convert function
            if (funcs[info].id == FunctionId.Convert)
            {
                if (argumentCount != 2)
                {
                    throw ExprException.FunctionArgumentCount(this.name);
                }

                argumentValues[0] = this.arguments[0].Eval(row, version);
                argumentValues[1] = GetDataType(this.arguments[1]);
            }
            else
            {
                for (int i = 0; i < this.argumentCount; i++)
                {
                    argumentValues[i] = this.arguments[i].Eval(row, version);

                    if (funcs[info].IsValidateArguments)
                    {
#if DEBUG
                        if (CompModSwitches.FunctionNode.TraceVerbose)
                        {
                            Debug.WriteLine("Validate arguments for " + funcs[info].name);
                        }
#endif
                        if ((argumentValues[i] == DBNull.Value) || (typeof(object) == funcs[info].parameters[i]))
                        {
#if DEBUG
                            if (CompModSwitches.FunctionNode.TraceVerbose)
                            {
                                Debug.WriteLine("argument " + (i + 1).ToString() + " is empty");
                            }
#endif

                            // currently all supported functions with IsValidateArguments set to true
                            // NOTE: for IIF and ISNULL IsValidateArguments set to false
                            return(DBNull.Value);
                        }

                        if (argumentValues[i].GetType() != funcs[info].parameters[i])
                        {
#if DEBUG
                            if (CompModSwitches.FunctionNode.TraceVerbose)
                            {
                                Debug.WriteLine("change argumnet " + argumentValues[i].ToString() + " to " + funcs[info].parameters[i].ToString());
                            }
#endif
                            // We are allowing conversions in one very specific case: int, int64,...'nice' numeric to numeric..

                            if (funcs[info].parameters[i] == typeof(int) && ExpressionNode.IsInteger(argumentValues[i].GetType()))
                            {
                                argumentValues[i] = Convert.ToInt32(argumentValues[i]);
                            }
                            else
                            {
                                throw ExprException.ArgumentType(funcs[info].name, i + 1, funcs[info].parameters[i]);
                            }
                        }
                    }
                }
            }
            return(EvalFunction(funcs[info].id, argumentValues, row, version));
        }