private Expression CombineExpressions(Expression expr1, Expression expr2, FilterStatementConnector connector) { return(connector == FilterStatementConnector.And ? Expression.AndAlso(expr1, expr2) : Expression.OrElse(expr1, expr2)); }
/// <summary> /// Adds a new <see cref="FilterStatement{TPropertyType}" /> to the <see cref="Filter{TClass}" />. /// (To be used by <see cref="Operation" /> that need no values) /// </summary> /// <param name="propertyId">Property identifier conventionalized by for the Expression Builder.</param> /// <param name="operation"></param> /// <param name="connector"></param> /// <returns></returns> public IFilterStatementConnection By(string propertyId, Operation operation, FilterStatementConnector connector = FilterStatementConnector.And) { return(By <string>(propertyId, operation, null, null, connector)); }
/// <summary> /// Adds a new <see cref="FilterStatement{TPropertyType}" /> to the <see cref="Filter{TClass}" />. /// </summary> /// <typeparam name="TPropertyType"></typeparam> /// <param name="propertyId">Property identifier conventionalized by for the Expression Builder.</param> /// <param name="operation"></param> /// <param name="value"></param> /// <param name="value2"></param> /// <param name="connector"></param> /// <returns></returns> public IFilterStatementConnection By <TPropertyType>(string propertyId, Operation operation, TPropertyType value, TPropertyType value2 = default(TPropertyType), FilterStatementConnector connector = FilterStatementConnector.And) { IFilterStatement statement = new FilterStatement <TPropertyType>(propertyId, operation, value, value2, connector); _statements.Add(statement); return(new FilterStatementConnection <TClass>(this, statement)); }
/// <summary> /// Instantiates a new <see cref="FilterStatement{TPropertyType}" />. /// </summary> /// <param name="propertyId"></param> /// <param name="operation"></param> /// <param name="value"></param> /// <param name="value2"></param> /// <param name="connector"></param> public FilterStatement(string propertyId, Operation operation, TPropertyType value, TPropertyType value2 = default(TPropertyType), FilterStatementConnector connector = FilterStatementConnector.And) { PropertyId = propertyId; Connector = connector; Operation = operation; if (typeof(TPropertyType).IsArray) { if (operation != Operation.Contains && operation != Operation.In) { throw new ArgumentException("Only 'Operacao.Contains' and 'Operacao.In' support arrays as parameters."); } var listType = typeof(List <>); var constructedListType = listType.MakeGenericType(typeof(TPropertyType).GetElementType()); Value = value != null?Activator.CreateInstance(constructedListType, value) : null; Value2 = value2 != null?Activator.CreateInstance(constructedListType, value2) : null; } else { Value = value; Value2 = value2; } Validate(); }