private static DbGatewayParameter MapParameter(object objectToMap, PropertyInfo propertyInfo) { DbGatewayParameter newParameter = null; object[] myAttribute = propertyInfo.GetCustomAttributes(false); foreach (object attr in myAttribute) { var isMappableAtt = attr as Mappable; if (isMappableAtt == null) continue; object mapValue = propertyInfo.GetValue(objectToMap, null); if (mapValue == null) continue; // if is Nullable type and its value is null don't map it; // Nullable Properties are defaulted to null in the stored procedure, therefore, // no need to set their values since the defualt value will be used. // if (propertyInfo.PropertyType.Name.Contains("Nullable") && mapValue == null) continue; if (mapValue is DateTime) { var dt = (DateTime)mapValue; if (dt == DateTime.MinValue) { mapValue = DBNull.Value; } } else if (mapValue.GetType() == typeof(List<string>)) { var values = (List<string>)mapValue; var strBld = new StringBuilder(); foreach (string str in values) { strBld.AppendFormat("{0}|", str); } mapValue = strBld.ToString().TrimEnd(','); } else if (mapValue.GetType().BaseType == typeof(Enum)) { mapValue = (int)mapValue; } string spParameterName = String.IsNullOrEmpty(isMappableAtt.SpParameter) ? propertyInfo.Name : isMappableAtt.SpParameter.Trim('@'); newParameter = new DbGatewayParameter("@" + spParameterName, mapValue, GetDbParameterType(propertyInfo.PropertyType)); newParameter.IsGet = isMappableAtt.IsSpGetParameter; newParameter.IsInsertUpdate = isMappableAtt.IsSpInsertUpdateParameter; } return newParameter; }
private static bool HasParameter(IEnumerable<DbGatewayParameter> parameters, DbGatewayParameter parameter) { foreach (DbGatewayParameter dbGatewayParameter in parameters) { if (dbGatewayParameter.ParameterName == parameter.ParameterName) return true; } return false; }