public static string GetExpression(DateFilterDescriptor dateTimeFilterDescriptor) { if (!dateTimeFilterDescriptor.IgnoreTimePart) { return(FilterDescriptor.GetExpression((FilterDescriptor)dateTimeFilterDescriptor)); } if (string.IsNullOrEmpty(dateTimeFilterDescriptor.PropertyName) || dateTimeFilterDescriptor.Operator == FilterOperator.None || dateTimeFilterDescriptor.Operator != FilterOperator.IsNotNull && dateTimeFilterDescriptor.Operator != FilterOperator.IsNull && !dateTimeFilterDescriptor.Value.HasValue) { return(string.Empty); } string str1 = (string)null; string str2 = (string)null; string str3 = DataStorageHelper.EscapeName(dateTimeFilterDescriptor.PropertyName); if (dateTimeFilterDescriptor.Value.HasValue) { str1 = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "#{0}#", (object)dateTimeFilterDescriptor.Value.Value.Date); str2 = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "#{0}#", (object)dateTimeFilterDescriptor.Value.Value.Date.AddDays(1.0)); } switch (dateTimeFilterDescriptor.Operator) { case FilterOperator.None: return(string.Empty); case FilterOperator.IsLike: case FilterOperator.IsEqualTo: return(string.Format("{0} >= {1} AND {0} < {2}", (object)str3, (object)str1, (object)str2)); case FilterOperator.IsNotLike: case FilterOperator.IsNotEqualTo: return(string.Format("{0} < {1} OR {0} >= {2}", (object)str3, (object)str1, (object)str2)); case FilterOperator.IsLessThan: return(string.Format("{0} < {1}", (object)str3, (object)str1)); case FilterOperator.IsLessThanOrEqualTo: return(string.Format("{0} < {1}", (object)str3, (object)str2)); case FilterOperator.IsGreaterThanOrEqualTo: return(string.Format("{0} >= {1}", (object)str3, (object)str1)); case FilterOperator.IsGreaterThan: return(string.Format("{0} >= {1}", (object)str3, (object)str2)); case FilterOperator.IsNull: return(string.Format("{0} IS NULL", (object)str3)); case FilterOperator.IsNotNull: return(string.Format("NOT ({0} IS NULL)", (object)str3)); default: return(string.Empty); } }
/// <summary> /// Gets the expression. /// </summary> /// <param name="dateTimeFilterDescriptor">The filter descriptor.</param> /// <returns></returns> public static string GetExpression(DateFilterDescriptor dateTimeFilterDescriptor) { if (dateTimeFilterDescriptor.IgnoreTimePart) { if (String.IsNullOrEmpty(dateTimeFilterDescriptor.PropertyName) || dateTimeFilterDescriptor.Operator == FilterOperator.None) { return(string.Empty); } if ((dateTimeFilterDescriptor.Operator != FilterOperator.IsNotNull && dateTimeFilterDescriptor.Operator != FilterOperator.IsNull) && dateTimeFilterDescriptor.Value == null) { return(string.Empty); } string dateBegin = null; string dateEnd = null; string propertyName = DataStorageHelper.EscapeName(dateTimeFilterDescriptor.PropertyName); if (dateTimeFilterDescriptor.Value != null) { dateBegin = String.Format(CultureInfo.InvariantCulture, "#{0}#", dateTimeFilterDescriptor.Value.Value.Date); dateEnd = String.Format(CultureInfo.InvariantCulture, "#{0}#", dateTimeFilterDescriptor.Value.Value.Date.AddDays(1)); } switch (dateTimeFilterDescriptor.Operator) { case FilterOperator.None: return(String.Empty); case FilterOperator.IsNull: return(string.Format("{0} IS NULL", propertyName)); case FilterOperator.IsNotNull: return(string.Format("NOT ({0} IS NULL)", propertyName)); case FilterOperator.IsLessThan: return(string.Format("{0} < {1}", propertyName, dateBegin)); case FilterOperator.IsLessThanOrEqualTo: return(string.Format("{0} < {1}", propertyName, dateEnd)); case FilterOperator.IsLike: case FilterOperator.IsEqualTo: return(string.Format("{0} >= {1} AND {0} < {2}", propertyName, dateBegin, dateEnd)); case FilterOperator.IsNotLike: case FilterOperator.IsNotEqualTo: return(string.Format("{0} < {1} OR {0} >= {2}", propertyName, dateBegin, dateEnd)); case FilterOperator.IsGreaterThanOrEqualTo: return(string.Format("{0} >= {1}", propertyName, dateBegin)); case FilterOperator.IsGreaterThan: return(string.Format("{0} >= {1}", propertyName, dateEnd)); case FilterOperator.StartsWith: case FilterOperator.EndsWith: case FilterOperator.Contains: case FilterOperator.NotContains: case FilterOperator.IsContainedIn: case FilterOperator.IsNotContainedIn: default: return(String.Empty); } } else { return(FilterDescriptor.GetExpression(dateTimeFilterDescriptor)); } }
/// <summary> /// Returns a <see cref="System.String"/> that represents this instance. /// </summary> /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> public override string ToString() { return(FilterDescriptor.GetExpression(this)); }
public static string GetExpression(FilterDescriptor filterDescriptor) { return(FilterDescriptor.GetExpression(filterDescriptor, (Function <FilterDescriptor, object>)null)); }
public static string GetCompositeExpression( CompositeFilterDescriptor filterDescriptor, Function <FilterDescriptor, object> formatValue) { StringBuilder stringBuilder = new StringBuilder(); for (int index = 0; index < filterDescriptor.filters.Count; ++index) { FilterDescriptor filter = filterDescriptor.filters[index]; CompositeFilterDescriptor filterDescriptor1 = filter as CompositeFilterDescriptor; if (filterDescriptor1 != null || !string.IsNullOrEmpty(filter.PropertyName)) { string str1 = filterDescriptor1 != null?CompositeFilterDescriptor.GetCompositeExpression(filterDescriptor1, formatValue) : FilterDescriptor.GetExpression(filter, formatValue); stringBuilder.Append(string.Format("{0}", (object)str1)); string str2 = filterDescriptor.filters.LogicalOperator == FilterLogicalOperator.And ? "AND" : "OR"; if (index < filterDescriptor.filters.Count - 1) { stringBuilder.Append(string.Format(" {0} ", (object)str2)); } } } if (stringBuilder.Length > 0) { stringBuilder.Insert(0, filterDescriptor.NotOperator ? "NOT (" : "("); stringBuilder.Append(")"); } return(stringBuilder.ToString()); }