public void TypeBasedExpressionRewriter_NoChange()
 {
     foreach (var e in new Expression[]
     {
         Expression.Constant(1L, typeof(long)),
         (Expression <Func <DateTimeOffset> >)(() => DateTimeOffset.Now),
         (Expression <Func <IEnumerable <long>, IEnumerable <string> > >)(xs => from x in xs where x % 2 == 0 select x.ToString())
     })
     {
         var rewriter = new TestRewriter();
         Assert.AreSame(e, rewriter.Visit(e));
     }
 }
        public void TypeBasedExpressionRewriter_NoChange()
        {
            foreach (var e in new Expression[]
            {
                Expression.Constant(1L, typeof(long)),
#pragma warning disable IDE0004 // Remove Unnecessary Cast. (Only unnecessary on C# 10 or later.)
                (Expression <Func <DateTimeOffset> >)(() => DateTimeOffset.Now),
#pragma warning restore IDE0004
                (Expression <Func <IEnumerable <long>, IEnumerable <string> > >)(xs => from x in xs where x % 2 == 0 select x.ToString())
            })
            {
                var rewriter = new TestRewriter();
                Assert.AreSame(e, rewriter.Visit(e));
            }
        }
        public void TypeBasedExpressionRewriter_Simple()
        {
            var f = new Foo {
                Value = 42
            };

            foreach (var e in new Dictionary <Expression, Expression>
            {
                { Expression.Constant(f, typeof(Foo)), Expression.Convert(Expression.Constant(f, typeof(Foo)), typeof(Bar)) },
                { (Expression <Func <Foo, Foo> >)(x => x.Other), (Expression <Func <Foo, Foo> >)(x => (Bar)((Bar)x).Other) },
                { (Expression <Func <Foo, Foo> >)(x => x), (Expression <Func <Foo, Foo> >)(x => (Bar)x) },
#pragma warning disable IDE0004 // Remove Unnecessary Cast. (Keeping inside expression tree.)
                { (Expression <Func <List <int>, IEnumerable <int> > >)(x => (IEnumerable <int>)x), (Expression <Func <List <int>, IEnumerable <int> > >)(x => (IEnumerable <int>)(IEnumerable <int>) x) },
#pragma warning restore IDE0004
            })
            {
                var comparer = new ExpressionEqualityComparer();
                var rewriter = new TestRewriter();
                Assert.IsTrue(comparer.Equals(rewriter.Visit(e.Key), e.Value));
            }
        }