System.Data.ExprException.DatatypeConvertion C# (CSharp) Метод

DatatypeConvertion() публичный статический Метод

public static DatatypeConvertion ( Type type1, Type type2 ) : Exception
type1 System.Type
type2 System.Type
Результат System.Exception
        public static Exception DatatypeConvertion(Type type1, Type type2)
        {
            return _Eval(SR.Format(SR.Expr_DatatypeConvertion, type1.ToString(), type2.ToString()));
        }

Usage Example

Пример #1
0
        private object EvalFunction(FunctionId id, object[] argumentValues, DataRow row, DataRowVersion version)
        {
            StorageType storageType;

            switch (id)
            {
            case FunctionId.Abs:
                Debug.Assert(_argumentCount == 1, "Invalid argument argumentCount for " + s_funcs[_info]._name + " : " + _argumentCount.ToString(FormatProvider));

                storageType = DataStorage.GetStorageType(argumentValues[0].GetType());
                if (ExpressionNode.IsInteger(storageType))
                {
                    return(Math.Abs((long)argumentValues[0]));
                }
                if (ExpressionNode.IsNumeric(storageType))
                {
                    return(Math.Abs((double)argumentValues[0]));
                }

                throw ExprException.ArgumentTypeInteger(s_funcs[_info]._name, 1);

            case FunctionId.cBool:
                Debug.Assert(_argumentCount == 1, "Invalid argument argumentCount for " + s_funcs[_info]._name + " : " + _argumentCount.ToString(FormatProvider));

                storageType = DataStorage.GetStorageType(argumentValues[0].GetType());
                return(storageType switch
                {
                    StorageType.Boolean => (bool)argumentValues[0],
                    StorageType.Int32 => ((int)argumentValues[0] != 0),
                    StorageType.Double => ((double)argumentValues[0] != 0.0),
                    StorageType.String => bool.Parse((string)argumentValues[0]),
                    _ => throw ExprException.DatatypeConvertion(argumentValues[0].GetType(), typeof(bool)),
                });
All Usage Examples Of System.Data.ExprException::DatatypeConvertion