public static bool _IsCasteable(string objectIn, out object resultOut, Utils.Constants.DATA_TYPES returnDataType) { bool isCasteable = false; if (returnDataType == Constants.DATA_TYPES.INT) { int intOut = 0; isCasteable = int.TryParse(objectIn, out intOut); resultOut = intOut; } else if (returnDataType == Constants.DATA_TYPES.BIGINT) { Int32 bigintOut = 0; isCasteable = Int32.TryParse(objectIn, out bigintOut); resultOut = bigintOut; } else if (returnDataType == Constants.DATA_TYPES.DOUBLE) { double doubleOut = 0; isCasteable = double.TryParse(objectIn, out doubleOut); resultOut = doubleOut; } else if (returnDataType == Constants.DATA_TYPES.FLOAT) { float floatOut = 0; isCasteable = float.TryParse(objectIn, out floatOut); resultOut = floatOut; } else if (returnDataType == Constants.DATA_TYPES.DATETIME) { DateTime dateTimeOut; isCasteable = DateTime.TryParse(objectIn, out dateTimeOut); resultOut = dateTimeOut; } else if (returnDataType == Constants.DATA_TYPES.BIT) { bool boolOut; isCasteable = Boolean.TryParse(objectIn, out boolOut); resultOut = boolOut; } else { resultOut = null; } return(isCasteable); }
protected object GetValueRecord(object recordObject, Utils.Constants.DATA_TYPES returnDataType) { object returnObject; if (recordObject != DBNull.Value) { switch (returnDataType) { case Utils.Constants.DATA_TYPES.DATETIME: if (!Utils.Utilities._IsCasteable(recordObject.ToString(), out returnObject, Utils.Constants.DATA_TYPES.DATETIME)) { Utils.Log.LoggerBase._Log(string.Format("The recordObject {0} is not a valid DATETIME", recordObject.ToString()), this.GetType()); } break; case Utils.Constants.DATA_TYPES.DOUBLE: if (!Utils.Utilities._IsCasteable(recordObject.ToString(), out returnObject, Utils.Constants.DATA_TYPES.DOUBLE)) { Utils.Log.LoggerBase._Log(string.Format("The recordObject {0} is not a valid DOUBLE", recordObject.ToString()), this.GetType()); } break; case Utils.Constants.DATA_TYPES.FLOAT: if (!Utils.Utilities._IsCasteable(recordObject.ToString(), out returnObject, Utils.Constants.DATA_TYPES.FLOAT)) { Utils.Log.LoggerBase._Log(string.Format("The recordObject {0} is not a valid FLOAT", recordObject.ToString()), this.GetType()); } break; case Utils.Constants.DATA_TYPES.INT: if (!Utils.Utilities._IsCasteable(recordObject.ToString(), out returnObject, Utils.Constants.DATA_TYPES.INT)) { Utils.Log.LoggerBase._Log(string.Format("The recordObject {0} is not a valid INT", recordObject.ToString()), this.GetType()); } break; case Utils.Constants.DATA_TYPES.BIGINT: if (!Utils.Utilities._IsCasteable(recordObject.ToString(), out returnObject, Utils.Constants.DATA_TYPES.BIGINT)) { Utils.Log.LoggerBase._Log(string.Format("The recordObject {0} is not a valid BIGINT", recordObject.ToString()), this.GetType()); } break; case Utils.Constants.DATA_TYPES.VARCHAR: case Utils.Constants.DATA_TYPES.NVARCHAR: returnObject = recordObject.ToString(); break; case Utils.Constants.DATA_TYPES.BIT: if (!Utils.Utilities._IsCasteable(recordObject.ToString(), out returnObject, Utils.Constants.DATA_TYPES.BIT)) { Utils.Log.LoggerBase._Log(string.Format("The recordObject {0} is not a valid BIT", recordObject.ToString()), this.GetType()); } break; } return(recordObject); } else { return(null); } }