private Domain(Domain d, bool keepCompilerData) : base(d.Span) { ComposeKind = d.ComposeKind; Name = d.Name; CompilerData = keepCompilerData ? d.CompilerData : null; }
public static IQueryable <TItem> AutoFilter <TItem, TFilter>( this IQueryable <TItem> query, TFilter filter, ComposeKind composeKind = ComposeKind.And) { var filtered = AutoFilterClass.Filter(query, filter, composeKind); return(filtered); }
private void StartDomain(string name, ComposeKind kind, Span span) { Contract.Requires(currentModule == null); var dom = new Domain(span, name, kind); parseResult.Program.Node.AddModule(dom); currentModule = dom; crntModRefState = ModRefState.Other; }
public static IQueryable <TItem> Filter <TItem, TFilter>(IQueryable <TItem> query, TFilter filter, ComposeKind composeKind = ComposeKind.And) { var expression = GetExpression <TItem, TFilter>(filter, composeKind, false); if (expression == null) { return(query); } return(query.Where(expression)); }
public static IQueryable <TSubject> AutoFilter <TSubject, TPredicate>( this IQueryable <TSubject> query, TPredicate predicate, ComposeKind composeKind = ComposeKind.And) { var filtered = Conventions <TSubject> .Filter(query, predicate, composeKind); var orderBy = FastTypeInfo <TPredicate> .PublicProperties.FirstOrDefault(x => x.Name == "OrderBy"); var proprtyName = orderBy?.GetValue(predicate, null) as string; return(proprtyName == null ? filtered : Conventions <TSubject> .Sort(filtered, proprtyName)); }
public static IQueryable <T> FilterByConventions <T>(this IQueryable <T> queryable, object filter, ComposeKind composeKind = ComposeKind.And) { if (filter == null) { throw new ArgumentNullException(nameof(filter)); } var spec = (Spec <T>) SpecBuilder <T> .Build((dynamic)filter, composeKind); return(spec != null ? queryable.Where(spec) : queryable); }
public static IEnumerable <TItem> Filter <TItem, TFilter>(IEnumerable <TItem> query, TFilter filter, ComposeKind composeKind = ComposeKind.And) { var expression = GetExpression <TItem, TFilter>(filter, composeKind, true); if (expression == null) { return(query); } return(query.Where(expression.AsFunc())); }
public static IQueryable <TSubject> Filter <TPredicate>(IQueryable <TSubject> query, TPredicate predicate, ComposeKind composeKind = ComposeKind.And) { var filterProps = FastTypeInfo <TPredicate> .PublicProperties .ToArray(); var filterPropNames = filterProps .Select(x => x.Name) .ToArray(); var modelType = typeof(TSubject); var stringType = typeof(string); var dateTimeType = typeof(DateTime); var dateTimeNullableType = typeof(DateTime?); var parameter = Expression.Parameter(modelType); var props = FastTypeInfo <TSubject> .PublicProperties .Where(x => filterPropNames.Contains(x.Name)) .Select(x => new { Property = x, Value = filterProps.Single(y => y.Name == x.Name).GetValue(predicate) }) .Where(x => x.Value != null) .Select(x => { var property = Expression.Property(parameter, x.Property); Expression value = Expression.Constant(x.Value); value = Expression.Convert(value, property.Type); var body = Conventions.Filters[property.Type](property, value); return(Expression.Lambda <Func <TSubject, bool> >(body, parameter)); }) .ToArray(); if (!props.Any()) { return(query); } var expr = composeKind == ComposeKind.And ? props.Aggregate((c, n) => c.And(n)) : props.Aggregate((c, n) => c.Or(n)); return(query.Where(expr)); }
public static Spec <T> ToSpec <T>(this object predicate, ComposeKind composeKind = ComposeKind.And) { var filterProps = predicate.GetType() .GetProperties() .Where(x => x.CanRead && x.CanWrite) .ToArray(); var filterPropNames = filterProps .Select(x => x.Name) .ToArray(); var modelType = typeof(T); var stringType = typeof(string); var dateTimeType = typeof(DateTime); var dateTimeNullableType = typeof(DateTime?); var parameter = Expression.Parameter(modelType); var props = FastTypeInfo <T> .PublicProperties .Where(x => filterPropNames.Contains(x.Name)) .Select(x => new { Property = x, Value = filterProps.Single(y => y.Name == x.Name).GetValue(predicate) }) .Where(x => x.Value != null) .Select(x => { var property = Expression.Property(parameter, x.Property); Expression value = Expression.Constant(x.Value); value = Expression.Convert(value, property.Type); var body = Conventions.Filters[property.Type](property, value); return(Expression.Lambda <Func <T, bool> >(body, parameter)); }) .ToArray(); if (!props.Any()) { return(null); } return(composeKind == ComposeKind.And ? props.Aggregate((c, n) => c.And(n)) : props.Aggregate((c, n) => c.Or(n))); }
internal Domain(Span span, string name, ComposeKind kind) : base(span) { Contract.Requires(name != null); Name = name; ComposeKind = kind; Config = new Config(span); compositions = new LinkedList <ModRef>(); Compositions = new ImmutableCollection <ModRef>(compositions); rules = new LinkedList <Rule>(); Rules = new ImmutableCollection <Rule>(rules); typeDecls = new LinkedList <Node>(); TypeDecls = new ImmutableCollection <Node>(typeDecls); conforms = new LinkedList <ContractItem>(); Conforms = new ImmutableCollection <ContractItem>(conforms); }
internal Model(Span span, string name, bool isPartial, ModRef domain, ComposeKind kind) : base(span) { Contract.Requires(!string.IsNullOrWhiteSpace(name)); Contract.Requires(domain != null); IsPartial = isPartial; Name = name; Domain = domain; ComposeKind = kind; includes = new LinkedList <ModRef>(); Compositions = new ImmutableCollection <ModRef>(includes); contracts = new LinkedList <ContractItem>(); Contracts = new ImmutableCollection <ContractItem>(contracts); facts = new LinkedList <ModelFact>(); Facts = new ImmutableCollection <ModelFact>(facts); Config = new Config(span); }
/// <summary> /// DO NOT USE - Mutating operation; only called by parser. /// </summary> /// <param name="modRef"></param> internal void SetCompose(ComposeKind kind) { Contract.Requires(ComposeKind == ComposeKind.None); ComposeKind = kind; }
/// <param name="composeKind">Specifies that multi Value expression compose kind.</param> public MultiValueAttribute(ComposeKind composeKind = ComposeKind.Or) => this.ComposeKind = composeKind;
public static Expression <Func <TItem, bool> >?CreateExpression <TItem, TFilter>(TFilter filter, ComposeKind composeKind = ComposeKind.And, bool addNullChecks = false) { var parameter = Expression.Parameter(typeof(TItem), "x"); var itemPropertyNames = ItemPropertyCache <TItem> .PropertyNames; var propertyExpressions = GetPropertiesExpressions(parameter, filter, addNullChecks, itemPropertyNames); if (!propertyExpressions.Any()) { return(null); } var body = composeKind == ComposeKind.And ? propertyExpressions.Aggregate(Expression.AndAlso) : propertyExpressions.Aggregate(Expression.OrElse); var result = Expression.Lambda <Func <TItem, bool> >(body, parameter); return(result); }
protected static Expression <Func <TItem, bool> > GetExpression <TItem, TFilter>(TFilter filter, ComposeKind composeKind, bool inMemory) { var parameter = Expression.Parameter(typeof(TItem)); var propertyExpressions = GetPropertiesExpressions(parameter, filter, inMemory); if (!propertyExpressions.Any()) { return(null); } var body = composeKind == ComposeKind.And ? propertyExpressions.Aggregate((c, n) => Expression.AndAlso(c, n)) : propertyExpressions.Aggregate((c, n) => Expression.OrElse(c, n)); var result = Expression.Lambda <Func <TItem, bool> >(body, parameter); return(result); }
private void SetCompose(ComposeKind kind) { Contract.Requires(currentModule != null); Contract.Requires(currentModule.NodeKind == NodeKind.Model); ((Model)currentModule).SetCompose(kind); }
public static Spec <TSubject> BuildSearch <TPredicate>(TPredicate predicate, ComposeKind composeKind = ComposeKind.Or) => SpecBuilder <TSubject, TPredicate> .BuildSearch(predicate, composeKind);
public static Spec <TSubject> Build <TPredicate>(TPredicate predicate, ComposeKind composeKind = ComposeKind.And) => SpecBuilder <TSubject, TPredicate> .Build(predicate, composeKind);
public static IQueryable <TSubject> AutoFilter <TSubject, TPredicate>( this IQueryable <TSubject> query, TPredicate predicate, ComposeKind composeKind = ComposeKind.And) => Conventions <TSubject> .Filter(query, predicate, composeKind);