private static object GetExpressionValue( FilterDescriptor filterDescriptor, Function <FilterDescriptor, object> formatValue) { object obj1 = filterDescriptor.Value; if (!(obj1 is string) && obj1 is IEnumerable) { IEnumerable enumerable = obj1 as IEnumerable; List <object> objectList = new List <object>(); foreach (object obj2 in enumerable) { FilterDescriptor filterDescriptor1 = filterDescriptor.Clone() as FilterDescriptor; filterDescriptor1.Value = obj2; object expressionValue = FilterDescriptor.GetExpressionValue(filterDescriptor1, formatValue); objectList.Add(expressionValue); } return((object)objectList.ToArray()); } object obj3 = formatValue != null?formatValue(filterDescriptor) : filterDescriptor.Value; object obj4; if (obj3 is string || obj3 is char || (obj3 is Guid || obj3 is TimeSpan)) { obj4 = (object)("'" + DataStorageHelper.EscapeValue(Convert.ToString(obj3)) + "'"); } else if (obj3 is Enum) { obj4 = (object)Convert.ToInt32(obj3); } else if (obj3 is DateTime) { obj4 = (object)string.Format((IFormatProvider)CultureInfo.InvariantCulture, "#{0}#", obj3); } else { obj4 = !(obj3 is double) ? (!(obj3 is Color) ? (obj3 is short || obj3 is int || (obj3 is long || obj3 is Decimal) || (obj3 is float || obj3 is double || obj3 is bool) ? (object)Convert.ToString(filterDescriptor.Value, (IFormatProvider)CultureInfo.InvariantCulture) : (object)("'" + DataStorageHelper.EscapeValue(Convert.ToString(filterDescriptor.Value, (IFormatProvider)CultureInfo.InvariantCulture)) + "'")) : (object)((Color)obj3).ToArgb()) : (object)((double)obj3).ToString("G17", (IFormatProvider)CultureInfo.InvariantCulture); } return(obj4); }
/// <summary> /// Gets the expression. /// </summary> /// <param name="filterDescriptor">The filter descriptor.</param> /// <returns></returns> public static string GetExpression(FilterDescriptor filterDescriptor) { if (string.IsNullOrEmpty(filterDescriptor.PropertyName) || filterDescriptor.filterOperator == FilterOperator.None) { return(string.Empty); } if ((filterDescriptor.Operator != FilterOperator.IsNotNull && filterDescriptor.Operator != FilterOperator.IsNull) && filterDescriptor.value == null) { return(string.Empty); } object value = filterDescriptor.Value; if (value is string || value is char) { value = "'" + DataStorageHelper.EscapeValue(Convert.ToString(value)) + "'"; } else if (value is Enum) { value = Convert.ToInt32(value); } else if (value is DateTime) { value = String.Format(CultureInfo.InvariantCulture, "#{0}#", value); } else if (value is double) { value = ((double)value).ToString("R", CultureInfo.InvariantCulture); } else { value = Convert.ToString(filterDescriptor.Value, CultureInfo.InvariantCulture); } string likeValue = String.Empty; string name = DataStorageHelper.EscapeName(filterDescriptor.PropertyName); switch (filterDescriptor.Operator) { case FilterOperator.IsLike: return(string.Format("{0} LIKE {1}", name, value)); case FilterOperator.IsNotLike: return(string.Format("{0} NOT LIKE {1}", name, value)); case FilterOperator.StartsWith: likeValue = DataStorageHelper.EscapeLikeValue(Convert.ToString(filterDescriptor.Value, CultureInfo.InvariantCulture)); return(string.Format("{0} LIKE '{1}%'", name, likeValue)); case FilterOperator.EndsWith: likeValue = DataStorageHelper.EscapeLikeValue(Convert.ToString(filterDescriptor.Value, CultureInfo.InvariantCulture)); return(string.Format("{0} LIKE '%{1}'", name, likeValue)); case FilterOperator.Contains: likeValue = DataStorageHelper.EscapeLikeValue(Convert.ToString(filterDescriptor.Value, CultureInfo.InvariantCulture)); return(string.Format("{0} LIKE '%{1}%'", name, likeValue)); case FilterOperator.NotContains: likeValue = DataStorageHelper.EscapeLikeValue(Convert.ToString(filterDescriptor.Value, CultureInfo.InvariantCulture)); return(string.Format("{0} NOT LIKE '%{1}%'", name, likeValue)); case FilterOperator.IsEqualTo: return(string.Format("{0} = {1}", name, value)); case FilterOperator.IsLessThan: return(string.Format("{0} < {1}", name, value)); case FilterOperator.IsLessThanOrEqualTo: return(string.Format("{0} <= {1}", name, value)); case FilterOperator.IsGreaterThan: return(string.Format("{0} > {1}", name, value)); case FilterOperator.IsGreaterThanOrEqualTo: return(string.Format("{0} >= {1}", name, value)); case FilterOperator.IsNotEqualTo: return(string.Format("{0} <> {1}", name, value)); case FilterOperator.IsNull: return(string.Format("{0} IS NULL", name)); case FilterOperator.IsNotNull: return(string.Format("NOT ({0} IS NULL)", name)); case FilterOperator.IsContainedIn: return(string.Format("{0} IN ({1})", name, value)); case FilterOperator.IsNotContainedIn: return(string.Format("{0} NOT IN ({1})", name, value)); } return(string.Empty); }