public static ConventionBase <IType, IValueExtractor> ValueByMethod( this ConventionBuilder <IType, IValueExtractor> source, Func <IMethod, bool> filter, Func <PropertyValueExtractor, PropertyValueExtractor> configurationDelegate ) => source .By(t => configurationDelegate(BuildRoutine.ValueExtractor() .ByPropertyValue(new MethodAsProperty( t.Methods.First(filter.And(o => o.HasNoParameters() && !o.ReturnsVoid())) )) )) .When(t => t.Methods.Any(filter.And(o => o.HasNoParameters() && !o.ReturnsVoid())));
public static Func <T1, T2, bool> Nand <T1, T2>(this Func <T1, T2, bool> a, Func <T1, T2, bool> b) { return((t1, t2) => { return !a.And(b)(t1, t2); }); }
public static Func <T, bool> Nand <T>(this Func <T, bool> a, Func <T, bool> b) { return((T t) => { return !a.And(b)(t); }); }
public EntityFrameworkExpressionTranslatorContext( ITypeResolver?typeResolver = null, ITypeInfoProvider?typeInfoProvider = null, IIsKnownTypeProvider?isKnownTypeProvider = null, Func <SystemLinq.Expression, bool>?canBeEvaluatedLocally = null, IDynamicObjectMapper?valueMapper = null) : base(typeResolver, typeInfoProvider, isKnownTypeProvider, canBeEvaluatedLocally.And(ExpressionEvaluator.CanBeEvaluated), valueMapper) { }
public async Task <IActionResult> Index(string sortOrder, string currentFilter, string searchString, int?pageNumber) { ViewBag.Title = "Usuários"; ViewData["CurrentSort"] = sortOrder; ViewData["UsuarioSortParm"] = String.IsNullOrEmpty(sortOrder) ? "usuariod" : ""; ViewData["DescUsuarioSortParm"] = sortOrder == "Usuarios" ? "usuario_desc" : "Usuarios"; if (searchString != null) { pageNumber = 1; } else { searchString = currentFilter; } ViewData["CurrentFilter"] = searchString; var usuario = await _usuarioRepo.GetAsync(); if (!String.IsNullOrEmpty(searchString)) { Func <Usuario, bool> WhereUsuario = u => true; WhereUsuario = WhereUsuario.And(u => u.IdUsuario.ToString().Contains(searchString.ToUpper())); WhereUsuario = WhereUsuario.Or(u => u.NmUsuario.ToString().ToLower().Contains(searchString.ToLower())); WhereUsuario = WhereUsuario.Or(u => u.EmailUsuario.ToString().Contains(searchString.ToUpper())); usuario = usuario.Where(WhereUsuario); } switch (sortOrder) { case "usuariod": usuario = usuario.OrderByDescending(s => s.IdUsuario); break; case "Usuarios": usuario = usuario.OrderBy(s => s.NmUsuario); break; case "usuario_desc": usuario = usuario.OrderByDescending(s => s.NmUsuario); break; default: usuario = usuario.OrderBy(s => s.NmUsuario); break; } int pageSize = 20; // Número de registros por Página return(View(PaginatedList <Usuario> .Create(usuario.AsQueryable(), pageNumber ?? 1, pageSize))); }
public JsonResult List(string keywords, int?skip, int?take, string sortField, string orderBy , int?status) { var xtake = 10; var xskip = 0; long total = 0; if (skip != null) { xskip = skip.Value; } if (take != null) { xtake = take.Value; } List <UserMessageTransaction> rows = new List <UserMessageTransaction>(); var typeEmail = (short)Enums.UserMessageType.Email; Func <UserMessageTransaction, bool> predicate = i => i.Type == typeEmail; if (!string.IsNullOrEmpty(keywords)) { predicate = predicate.And(i => i.To.Contains(keywords) || i.Subject.Contains(keywords) || i.ToName.Contains(keywords)); } if (status != null && status >= 0) { predicate = predicate.And(i => i.Status == status); } using (var db = new CoreEcommerceDbContext()) { var query = db.UserMessageTransactions.Where(predicate); total = query.LongCount(); rows = query.OrderByDescending(i => i.SendDate).Skip(xskip).Take(xtake).ToList(); } return(Json(new { total, rows, success = true }, JsonRequestBehavior.AllowGet)); }
public void Should_Be_True() { Func <int, bool> IsEven = x => x % 2 == 0; Func <int, Func <int, bool> > GreaterThan = a => b => b > a; Func <int, Func <int, bool> > LessThan = a => b => b < a; Func <int, bool> Run = IsEven.And( GreaterThan(10), LessThan(20) ); Assert.True(Run(12)); Assert.False(Run(2)); Assert.False(Run(22)); }
public void AndTest1() { Func <Context, Fuzzy> first = context => Fuzzy.Create(context.Value); Fuzzy second(Context context) => Fuzzy.Create(context.Value).Not(); var context = new Context() { Value = 0.7 }; var firstFunc = STMNT.Is(first.And(second)); var secondFunc = STMNT.Is(first).And(second); var resultFirst = firstFunc(context); var resultSecond = secondFunc(context); Assert.Equal(resultFirst.Value, resultSecond.Value); }
public static void And() { //this example shows how to combine 2 predicates together //create 2 collections var primes = new[] { 2, 3, 5, 7, 11, 13, 17, 19 }; var fibo = new[] { 1, 2, 3, 5, 8, 13, 21, 34 }; //create 2 predicates Func <int, bool> isPrime = x => x.In(primes); Func <int, bool> isFibo = x => x.In(fibo); //using predicate.And(predicate2) create new predicate var isFiboPrime = isPrime.And(isFibo); //test with number 1 - 20 var fiboPrime = 1.To(20).Where(isFiboPrime); //show result Console.WriteLine(fiboPrime.ToString(", ")); }
public static IQueryable <T> CreateEntityFrameworkCoreAsyncQueryable <T>(this RemoteQueryableFactory factory, Func <Expressions.Expression, Task <IEnumerable <DynamicObject> > > dataProvider, ITypeInfoProvider typeInfoProvider = null, IDynamicObjectMapper mapper = null, Func <System.Linq.Expressions.Expression, bool> canBeEvaluatedLocally = null) => factory.CreateQueryable <T>(dataProvider, typeInfoProvider, mapper, canBeEvaluatedLocally.And(ExpressionEvaluator.CanBeEvaluated));
protected EntityFrameworkCoreExpressionExecutor(DbContext dbContext, ITypeResolver?typeResolver = null, Func <System.Linq.Expressions.Expression, bool>?canBeEvaluatedLocally = null) : this(dbContext.GetQueryableSetProvider(), typeResolver, canBeEvaluatedLocally.And(ExpressionEvaluator.CanBeEvaluated)) { }
public IList <PlayaDeEstacionamiento> BuscarPlayasPorFiltro(string idCiudad, int[] tipoPlaya, int[] tipoVehiculo, int[] diasAtencion, decimal precioHasta, int horaDesde, int horaHasta) { Func <PlayaDeEstacionamiento, bool> consulta = p => !p.FechaBaja.HasValue; if (!string.IsNullOrEmpty(idCiudad)) { consulta = consulta.And(p => p.IdPlaceCiudad.Trim().Equals(idCiudad.Trim(), StringComparison.OrdinalIgnoreCase)); } if (tipoPlaya.Length != 0) { if (consulta != null) { consulta = consulta.And(p => tipoPlaya.Contains(p.TipoPlayaId)); } else { consulta = p => tipoPlaya.Contains(p.TipoPlayaId); } } if (tipoVehiculo.Length != 0) { if (consulta != null) { consulta = consulta.And(p => p.Servicios.Any(s => tipoVehiculo.Contains(s.TipoVehiculoId))); } else { consulta = p => p.Servicios.Any(s => tipoVehiculo.Contains(s.TipoVehiculoId)); } } if (diasAtencion.Length != 0) { if (consulta != null) { consulta = consulta.And(p => diasAtencion.Contains(p.Horario.DiaAtencionId)); } else { consulta = p => diasAtencion.Contains(p.Horario.DiaAtencionId); } } if (precioHasta != 0) { if (consulta != null) { consulta = consulta.And(p => p.Servicios.Any(s => tipoVehiculo.Contains(s.TipoVehiculoId) && s.Precios.Any(prec => prec.TiempoId == 1 && prec.Monto <= precioHasta && prec.Monto > 0))); } else { consulta = p => p.Servicios.Any(s => tipoVehiculo.Contains(s.TipoVehiculoId) && s.Precios.Any(prec => prec.TiempoId == 1 && prec.Monto <= precioHasta && prec.Monto > 0)); } } if (horaDesde != 0) { if (consulta != null) { consulta = consulta.And(p => int.Parse(p.Horario.HoraDesde.Substring(0, 2)) <= horaDesde); } else { consulta = p => int.Parse(p.Horario.HoraDesde.Substring(0, 2)) <= horaDesde; } } if (horaHasta != 0) { if (consulta != null) { consulta = consulta.And(p => int.Parse(p.Horario.HoraHasta.Substring(0, 2)) >= horaHasta); } else { consulta = p => int.Parse(p.Horario.HoraHasta.Substring(0, 2)) >= horaHasta; } } var listaPlayas = playaDao.FindWhere(consulta); return(listaPlayas); }
public EntityFrameworkCoreExpressionExecutor(DbContext dbContext, ITypeResolver typeResolver = null, IDynamicObjectMapper mapper = null, Func <Type, bool> setTypeInformation = null, Func <System.Linq.Expressions.Expression, bool> canBeEvaluatedLocally = null) : this(GetQueryableSetProvider(dbContext), typeResolver, mapper, setTypeInformation, canBeEvaluatedLocally.And(ExpressionEvaluator.CanBeEvaluated)) { }
public static Func <T1, T2, T3, T4, bool> Xor <T1, T2, T3, T4>(this Func <T1, T2, T3, T4, bool> a, Func <T1, T2, T3, T4, bool> b) { return((t1, t2, t3, t4) => { return a.Or(b)(t1, t2, t3, t4) && !a.And(b)(t1, t2, t3, t4); }); }
public static Func <T1, T2, T3, T4, T5, T6, T7, bool> Nand <T1, T2, T3, T4, T5, T6, T7>(this Func <T1, T2, T3, T4, T5, T6, T7, bool> a, Func <T1, T2, T3, T4, T5, T6, T7, bool> b) { return((t1, t2, t3, t4, t5, t6, t7) => !a.And(b)(t1, t2, t3, t4, t5, t6, t7)); }
/// <summary> /// IfHostNameContains returns a predicate which returns true if the hostname contains the given substring. /// </summary> /// <param name="predicate">The initial predicate.</param> /// <param name="hostNameSubstring">The substring for which to search.</param> /// <returns>The relevant selector.</returns> public static Func <Session, bool> IfHostNameContains(this Func <Session, bool> predicate, string hostNameSubstring) { return(predicate.And(Selectors.IfHostNameContains(hostNameSubstring))); }
/// <summary> /// IfUrlEquals returns a predicate which returns true if the URL in the session matches the given URL. /// </summary> /// <param name="predicate">The initial predicate.</param> /// <param name="urlToMatch">The URL to match.</param> /// <returns>The relevant selector.</returns> public static Func <Session, bool> IfUrlEquals(this Func <Session, bool> predicate, string urlToMatch) { return(predicate.And(Selectors.IfUrlEquals(urlToMatch))); }
/// <summary> /// SkipNSessions returns a predicate which always returns true after n invocations. /// </summary> /// <param name="predicate">The initial predicate.</param> /// <param name="n">How many sessions to skip.</param> /// <returns>The relevant selector.</returns> public static Func <Session, bool> SkipNSessions(this Func <Session, bool> predicate, int n) { return(predicate.And(Selectors.SkipNSessions(n))); }
public static Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool> Nand <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(this Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool> a, Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool> b) { return((t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => !a.And(b)(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10)); }
public static Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, bool> Xor <T1, T2, T3, T4, T5, T6, T7, T8, T9>(this Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, bool> a, Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, bool> b) { return((t1, t2, t3, t4, t5, t6, t7, t8, t9) => a.Or(b)(t1, t2, t3, t4, t5, t6, t7, t8, t9) && !a.And(b)(t1, t2, t3, t4, t5, t6, t7, t8, t9)); }
public static Func <T1, T2, T3, T4, T5, bool> Nand <T1, T2, T3, T4, T5>(this Func <T1, T2, T3, T4, T5, bool> a, Func <T1, T2, T3, T4, T5, bool> b) { return((t1, t2, t3, t4, t5) => !a.And(b)(t1, t2, t3, t4, t5)); }
public static IQueryable CreateEntityFrameworkCoreAsyncQueryable(this RemoteQueryableFactory factory, Type elementType, Func <Expressions.Expression, Task <object> > dataProvider, ITypeInfoProvider typeInfoProvider = null, IAsyncQueryResultMapper <object> resultMapper = null, Func <System.Linq.Expressions.Expression, bool> canBeEvaluatedLocally = null) => factory.CreateQueryable(elementType, dataProvider, typeInfoProvider, resultMapper, canBeEvaluatedLocally.And(ExpressionEvaluator.CanBeEvaluated));
public static IQueryable <T> CreateEntityFrameworkCoreAsyncQueryable <T, TSource>(this RemoteQueryableFactory factory, Func <Expressions.Expression, Task <TSource> > dataProvider, IAsyncQueryResultMapper <TSource> resultMapper, ITypeInfoProvider typeInfoProvider = null, Func <System.Linq.Expressions.Expression, bool> canBeEvaluatedLocally = null) => factory.CreateQueryable <T, TSource>(dataProvider, resultMapper, typeInfoProvider, canBeEvaluatedLocally.And(ExpressionEvaluator.CanBeEvaluated));
public static Func <T1, T2, T3, T4, T5, T6, bool> Xor <T1, T2, T3, T4, T5, T6>(this Func <T1, T2, T3, T4, T5, T6, bool> a, Func <T1, T2, T3, T4, T5, T6, bool> b) { return((t1, t2, t3, t4, t5, t6) => a.Or(b)(t1, t2, t3, t4, t5, t6) && !a.And(b)(t1, t2, t3, t4, t5, t6)); }
/// <summary> /// IfDelete returns a selector that adds a test for the GET verb. /// </summary> /// <param name="predicate">The initial predicate.</param> /// <returns>The relevant selector.</returns> public static Func <Session, bool> IfDelete(this Func <Session, bool> predicate) { return(predicate.And(Selectors.IfDelete())); }
public static IQueryable CreateEntityFrameworkCoreQueryable(this RemoteQueryableFactory factory, Type elementType, Func <Expressions.Expression, IEnumerable <DynamicObject> > dataProvider, ITypeInfoProvider?typeInfoProvider = null, IDynamicObjectMapper?mapper = null, Func <System.Linq.Expressions.Expression, bool>?canBeEvaluatedLocally = null) => factory.CreateQueryable(elementType, dataProvider, typeInfoProvider, mapper, canBeEvaluatedLocally.And(ExpressionEvaluator.CanBeEvaluated));
/// <summary> /// IfUrlContains returns a predicate which returns true if the URL contains the given substring of a URL. /// </summary> /// <param name="predicate">The initial predicate.</param> /// <param name="urlSubstring">The substring for which to search.</param> /// <returns>The relevant selector.</returns> public static Func <Session, bool> IfUrlContains(this Func <Session, bool> predicate, string urlSubstring) { return(predicate.And(Selectors.IfUrlContains(urlSubstring))); }
public static IQueryable CreateEntityFrameworkCoreQueryable <TSource>(this RemoteQueryableFactory factory, Type elementType, Func <Expressions.Expression, TSource> dataProvider, IQueryResultMapper <TSource> resultMapper, ITypeInfoProvider?typeInfoProvider = null, Func <System.Linq.Expressions.Expression, bool>?canBeEvaluatedLocally = null) => factory.CreateQueryable <TSource>(elementType, dataProvider, resultMapper, typeInfoProvider, canBeEvaluatedLocally.And(ExpressionEvaluator.CanBeEvaluated));
/// <summary> /// Alternating returns a predicate which returns true, then false, then true, and so forth. /// </summary> /// <param name="predicate">The initial predicate.</param> /// <param name="initialState">The initial state of the alternating selector.</param> /// <returns>The relevant selector.</returns> public static Func <Session, bool> Alternating(this Func <Session, bool> predicate, bool initialState = true) { return(predicate.And(Selectors.Alternating(initialState))); }
public static IQueryable <T> CreateEntityFrameworkCoreQueryable <T>(this RemoteQueryableFactory factory, Func <Expressions.Expression, IAsyncEnumerable <object?> > dataProvider, IQueryResultMapper <object?>?resultMapper = null, ITypeInfoProvider?typeInfoProvider = null, Func <System.Linq.Expressions.Expression, bool>?canBeEvaluatedLocally = null) => factory.CreateQueryable <T>(dataProvider, typeInfoProvider, resultMapper, canBeEvaluatedLocally.And(ExpressionEvaluator.CanBeEvaluated));