Skip to content

Instantly share code, notes, and snippets.

public static class ExpressionLogicalOperators
{
public static Expression<Func<T, bool>> And<T>(
Expression<Func<T, bool>> expr1,
Expression<Func<T, bool>> expr2)
{
var parameter = Expression.Parameter(typeof(T), expr1.Parameters[0].Name);
var left = ExpressionHelper.ReplaceParameter(expr1.Body, expr1.Parameters[0], parameter);
var right = ExpressionHelper.ReplaceParameter(expr2.Body, expr2.Parameters[0], parameter);
var body = Expression.AndAlso(left, right);
using System;
using System.Collections.Generic;
using System.Linq;
namespace Extensions.Linq
{
public static class XEnumerable
{
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source) where T : class =>
source.Where(x => x is {})!;
void Main()
{
Expression<Func<Test, Test>> f = x => x;
var r = new Test[0].AsQueryable().Append(new Test(444)).Select(q => new { A = q.X.ToString(), F = f.Apply(q).Double() }).Expand();
r.Expression.ToString().Dump();
r.ToArray().Dump();
var query2 = new[] { new { A = 10, B = new[] { "Hello", "Worlddd" } } }.AsQueryable();
Expression<Func<int, int>> fa1 = x => x * 1;
var r2 = query2.Select(x => new
private static IEqualityComparer<T> GetInstance()
{
var type = typeof(T);
ParameterExpression[] parameters =
{
Expression.Parameter(type, "x"),
Expression.Parameter(type, "y")
};
var result = type.GetProperties().Aggregate<PropertyInfo, Expression>(