System.Data.DataExpression.ToBoolean C# (CSharp) Method

ToBoolean() static private method

static private ToBoolean ( object value ) : bool
value object
return bool
        internal static bool ToBoolean(object value)
        {
            if (IsUnknown(value))
                return false;
            if (value is bool)
                return (bool)value;
            if (value is SqlBoolean)
            {
                return (((SqlBoolean)value).IsTrue);
            }
            //check for SqlString is not added, value for true and false should be given with String, not with SqlString
            if (value is string)
            {
                try
                {
                    return bool.Parse((string)value);
                }
                catch (Exception e) when (ADP.IsCatchableExceptionType(e))
                {
                    ExceptionBuilder.TraceExceptionForCapture(e);
                    throw ExprException.DatavalueConvertion(value, typeof(bool), e);
                }
            }

            throw ExprException.DatavalueConvertion(value, typeof(bool), null);
        }
    }

Usage Example

Example #1
0
        private bool AcceptRecord(int record)
        {
            DataRow row = table.recordManager[record];

            if (row == null)
            {
                return(true);
            }

            //

            DataRowVersion version = DataRowVersion.Default;

            if (row.oldRecord == record)
            {
                version = DataRowVersion.Original;
            }
            else if (row.newRecord == record)
            {
                version = DataRowVersion.Current;
            }
            else if (row.tempRecord == record)
            {
                version = DataRowVersion.Proposed;
            }

            object val = this.linearExpression.Eval(row, version);
            bool   result;

            try {
                result = DataExpression.ToBoolean(val);
            }
            catch (Exception e) {
                //
                if (!ADP.IsCatchableExceptionType(e))
                {
                    throw;
                }
                throw ExprException.FilterConvertion(this.rowFilter.Expression);
            }
            return(result);
        }
All Usage Examples Of System.Data.DataExpression::ToBoolean