public static List <SqlParameter> BuildParameters(DataRequest dataRequest) { var sqlParameters = new List <SqlParameter>(); var properties = dataRequest.GetType().GetProperties(); foreach (PropertyInfo prop in properties) { var propertyValue = prop.GetValue(dataRequest, null); // TODO: REFACTOR; IN THE CURRENT STATE WE MAY END UP WITH INFINITELY LONG SWITCH CASE if ((propertyValue != null) && !string.IsNullOrEmpty(propertyValue.ToString().ToLower()) && (propertyValue.ToString().ToLower() != "all")) { switch (prop.Name) { case "AllWithOrWithoutFilters": if (propertyValue.ToString().ToLower() == "without") { sqlParameters.Add(new SqlParameter("@HasWorkOrder", false)); } else if (propertyValue.ToString().ToLower() == "with") { sqlParameters.Add(new SqlParameter("@HasWorkOrder", true)); } break; case "StartDate": case "EndDate": var dateValue = new DateTime(); if (DateTime.TryParse(propertyValue.ToString(), out dateValue)) { sqlParameters = sqlParameters.Update(new SqlParameter($"@{prop.Name}", dateValue)); } break; case "ImagePath": //DO NOTHING break; default: sqlParameters.Add(new SqlParameter($"@{prop.Name}", propertyValue)); break; } } } return(sqlParameters); }