public static DatavalueConvertion ( object value, |
||
value | object | |
type | ||
innerException | ||
return |
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); }
internal object Evaluate(DataRow row, DataRowVersion version) { object result; if (!_bound) { Bind(_table); } if (_expr != null) { result = _expr.Eval(row, version); // if the type is a SqlType (StorageType.Uri < _storageType), convert DBNull values. if (result != DBNull.Value || StorageType.Uri < _storageType) { // we need to convert the return value to the column.Type; try { if (StorageType.Object != _storageType) { result = SqlConvert.ChangeType2(result, _storageType, _dataType, _table.FormatProvider); } } catch (Exception e) when(ADP.IsCatchableExceptionType(e)) { ExceptionBuilder.TraceExceptionForCapture(e); throw ExprException.DatavalueConvertion(result, _dataType, e); } } } else { result = null; } return(result); }
internal static bool ToBoolean(object value, bool strict) { if (IsUnknown(value)) { return(false); } if (value is bool) { return((bool)value); } if (value is string) { try { return(Boolean.Parse((string)value)); } catch (Exception) { // CONSIDER: keep the original exception, add it to the error text throw ExprException.DatavalueConvertion(value, typeof(bool)); } } if (!strict) { // convert whole numeric values to boolean: if (ExpressionNode.IsInteger(value.GetType())) { return((Int64)value != 0); } } throw ExprException.DatavalueConvertion(value, typeof(bool)); }
/// <include file='doc\DataExpression.uex' path='docs/doc[@for="DataExpression.Evaluate1"]/*' /> public virtual object Evaluate(DataRow row, DataRowVersion version) { object result; if (!bound) { this.Bind(this.table); } if (expr != null) { result = expr.Eval(row, version); if (result != DBNull.Value) { // we need to convert the return value to the column.Type; try { if (typeof(object) != this.type) { result = Convert.ChangeType(result, this.type); } } catch (Exception) { // CONSIDER: keep the original exception, add it to the error text // CONSIDER: Get the column name in the error to know which computation is failing. throw ExprException.DatavalueConvertion(result, type); } } } else { result = null; } return(result); }
internal object Evaluate(DataRow row, DataRowVersion version) { if (!this.bound) { this.Bind(this.table); } if (this.expr != null) { object obj2 = this.expr.Eval(row, version); if ((obj2 == DBNull.Value) && (StorageType.Uri >= this._storageType)) { return(obj2); } try { if (StorageType.Object != this._storageType) { obj2 = SqlConvert.ChangeType2(obj2, this._storageType, this._dataType, this.table.FormatProvider); } return(obj2); } catch (Exception exception) { if (!ADP.IsCatchableExceptionType(exception)) { throw; } ExceptionBuilder.TraceExceptionForCapture(exception); throw ExprException.DatavalueConvertion(obj2, this._dataType, exception); } } return(null); }
internal static bool ToBoolean(object value) { if (IsUnknown(value)) { return(false); } if (value is bool) { return((bool)value); } if (value is SqlBoolean) { SqlBoolean flag2 = (SqlBoolean)value; return(flag2.IsTrue); } if (value is string) { try { return(bool.Parse((string)value)); } catch (Exception exception) { if (!ADP.IsCatchableExceptionType(exception)) { throw; } ExceptionBuilder.TraceExceptionForCapture(exception); throw ExprException.DatavalueConvertion(value, typeof(bool), exception); } } throw ExprException.DatavalueConvertion(value, typeof(bool), null); }