public void ExpressionMemberAllowListScannerBase_NoPass()
        {
            var aps = new NoPassScanner();

            foreach (var e in new Expression[] {
                (Expression <Func <int, int> >)(x => - x),
                (Expression <Func <int, int, int> >)((a, b) => a + b),
            })
            {
                Assert.AreSame(e, aps.Visit(e));
            }

            foreach (var e in new Expression[] {
                (Expression <Func <TimeSpan, TimeSpan> >)(t => - t),
                (Expression <Func <DateTime, TimeSpan, DateTime> >)((d, t) => d + t),
#pragma warning disable IDE0004 // Remove Unnecessary Cast. (Only unnecessary on C# 10 or later.)
                (Expression <Func <DateTime> >)(() => DateTime.Now),
                (Expression <Func <DateTime, int> >)(d => d.Year),
                (Expression <Func <string, string> >)(s => s.ToUpper()),
                (Expression <Func <string, bool> >)(s => string.IsNullOrEmpty(s)),
                (Expression <Func <TimeSpan> >)(() => new TimeSpan(1, 2, 3)),
                Expression.MakeIndex(Expression.Parameter(typeof(Dictionary <int, int>)), typeof(Dictionary <int, int>).GetProperty("Item"), new[] { Expression.Constant(1) }),
                (Expression <Func <List <int> > >)(() => new List <int> {
                    1
                }),
                (Expression <Func <Bar> >)(() => new Bar {
                    Foo = 1
                }),
#pragma warning restore IDE0004
            })
            {
                Assert.ThrowsException <NotSupportedException>(() => aps.Visit(e));
            }
        }
Exemple #2
0
        public void ExpressionTypeAllowListScannerBase_NoPass()
        {
            var aps = new NoPassScanner();

            foreach (var e in new Expression[] {
                (Expression <Func <int, int> >)(x => - x),
                (Expression <Func <int, int, int> >)((a, b) => a + b),
                (Expression <Func <TimeSpan, TimeSpan> >)(t => - t),
                (Expression <Func <DateTime, TimeSpan, DateTime> >)((d, t) => d + t),
                (Expression <Func <DateTime> >)(() => DateTime.Now),
                (Expression <Func <DateTime, int> >)(d => d.Year),
                (Expression <Func <string, string> >)(s => s.ToUpper()),
                (Expression <Func <string, bool> >)(s => string.IsNullOrEmpty(s)),
                (Expression <Func <TimeSpan> >)(() => new TimeSpan(1, 2, 3)),
                Expression.MakeIndex(Expression.Parameter(typeof(Dictionary <int, int>)), typeof(Dictionary <int, int>).GetProperty("Item"), new[] { Expression.Constant(1) }),
                (Expression <Func <List <int> > >)(() => new List <int> {
                    1
                }),
            })
            {
                Assert.ThrowsException <NotSupportedException>(() => aps.Visit(e));
            }
        }