protected void CheckSettingsFirstRowCell(ColumnRole columnRole, ColumnType columnType, DataColumn dataColumn, object value, string[] messages) { var columnName = dataColumn.ColumnName; if (!DBNull.Value.Equals(value)) { if (columnRole != ColumnRole.Ignore) { if (columnType == ColumnType.Numeric && IsNumericField(dataColumn)) { return; } var numericCaster = new NumericCaster(); if (columnType == ColumnType.Numeric && !(numericCaster.IsValid(value) || BaseComparer.IsValidInterval(value))) { var exception = string.Format(messages[0] , columnName, value.ToString()); if (numericCaster.IsValid(value.ToString().Replace(",", "."))) { exception += messages[1]; } throw new EquivalerException(exception); } if (columnType == ColumnType.DateTime && IsDateTimeField(dataColumn)) { return; } if (columnType == ColumnType.DateTime && !BaseComparer.IsValidDateTime(value.ToString())) { throw new EquivalerException( string.Format(messages[2] , columnName, value.ToString())); } } } }
private Decimal?CastToNumeric(object obj) { if (obj == null) { return(null); } var caster = new NumericCaster(); if (caster.IsValid(obj)) { return(caster.Execute(obj)); } throw new ArgumentException(); }