private List <TItem> ApplyFilter <TItem>(IFilterOperation filterOperation, string operand, IEnumerable <TItem> items) { var dataSchema = new DataSchema(); var columnDescriptor = ColumnDescriptor.RootColumn(dataSchema, typeof(TItem)); if (null == operand) { Assert.IsNull(filterOperation.GetOperandType(columnDescriptor)); } else { Assert.IsNotNull(filterOperation.GetOperandType(columnDescriptor)); } var predicate = filterOperation.MakePredicate(columnDescriptor, operand); return(items.Where(item => predicate(item)).ToList()); }
private List <TItem> ApplyFilter <TItem>(IFilterOperation filterOperation, string operand, IEnumerable <TItem> items) { var dataSchema = new DataSchema(new DataSchemaLocalizer(CultureInfo.CurrentCulture)); var columnDescriptor = ColumnDescriptor.RootColumn(dataSchema, typeof(TItem)); if (null != operand) { Assert.IsNotNull(filterOperation.GetOperandType(columnDescriptor)); } var filterPredicate = FilterPredicate.CreateFilterPredicate(dataSchema, typeof(TItem), filterOperation, operand); var predicate = filterPredicate.MakePredicate(dataSchema, typeof(TItem)); return(items.Where(item => predicate(item)).ToList()); }
/// <summary> /// Constructs a new FilterPredicate from a value that the user has typed in the user interface. /// "operandText" is expected to be formatted according to the locale settings of "dataSchema". /// </summary> public static FilterPredicate CreateFilterPredicate(DataSchema dataSchema, Type columnType, IFilterOperation filterOperation, string operandText) { object operandValue; if (string.IsNullOrEmpty(operandText)) { operandValue = null; } else { Type operandType = filterOperation.GetOperandType(dataSchema, columnType); if (null == operandType) { operandValue = null; } else { operandValue = ParseOperandValue(dataSchema.DataSchemaLocalizer.FormatProvider, operandType, operandText); } } string invariantOperandText = OperandValueToString(CultureInfo.InvariantCulture, operandValue); return(new FilterPredicate(filterOperation, invariantOperandText)); }