public void ExpressionMemberAllowListScannerBase_Custom()
        {
            var cps = new CustomScanner();

            foreach (var e in new Expression[] {
                (Expression <Func <string, string> >)(s => s.ToLower()),
#pragma warning disable IDE0004 // Remove Unnecessary Cast. (Only unnecessary on C# 10 or later.)
                (Expression <Func <Bar> >)(() => new Bar {
                    Foo = 1
                }),
                (Expression <Func <List <int> > >)(() => new List <int> {
                    2
                }),
#pragma warning restore IDE0004
            })
            {
                Assert.AreSame(e, cps.Visit(e));
            }

            foreach (var e in new Expression[] {
                (Expression <Func <string, string> >)(s => s.TrimStart()),
#pragma warning disable IDE0004 // Remove Unnecessary Cast. (Only unnecessary on C# 10 or later.)
                (Expression <Func <Bar> >)(() => new Bar {
                    Qux = 1
                }),
                (Expression <Func <Dictionary <string, int> > >)(() => new Dictionary <string, int> {
                    { "bar", 2 }
                }),
#pragma warning restore IDE0004
            })
            {
                Assert.ThrowsException <NotSupportedException>(() => cps.Visit(e));
            }
        }
        public void ExpressionMemberAllowListScannerBase_Custom()
        {
            var cps = new CustomScanner();

            foreach (var e in new Expression[] {
                (Expression <Func <string, string> >)(s => s.ToLower()),
                (Expression <Func <Bar> >)(() => new Bar {
                    Foo = 1
                }),
                (Expression <Func <List <int> > >)(() => new List <int> {
                    2
                }),
            })
            {
                Assert.AreSame(e, cps.Visit(e));
            }

            foreach (var e in new Expression[] {
                (Expression <Func <string, string> >)(s => s.TrimStart()),
                (Expression <Func <Bar> >)(() => new Bar {
                    Qux = 1
                }),
                (Expression <Func <Dictionary <string, int> > >)(() => new Dictionary <string, int> {
                    { "bar", 2 }
                }),
            })
            {
                Assert.ThrowsException <NotSupportedException>(() => cps.Visit(e));
            }
        }
示例#3
0
        public void ExpressionTypeAllowListScannerBase_Custom()
        {
            var cps = new CustomScanner();

            foreach (var e in new Expression[]
            {
                (Expression <Func <DateTime, DateTime> >)(x => x),
                (Expression <Func <TimeSpan, TimeSpan> >)(x => x),
            })
            {
                Assert.AreSame(e, cps.Visit(e));
            }

            foreach (var e in new Expression[]
            {
                (Expression <Func <Int32, Int32> >)(x => x),
            })
            {
                Assert.ThrowsException <NotSupportedException>(() => cps.Visit(e));
            }
        }
示例#4
0
        public void ExpressionTypeAllowListScannerBase_Custom()
        {
            var cps = new CustomScanner();

            foreach (var e in new Expression[]
            {
                (Expression <Func <DateTime, DateTime> >)(x => x),
                (Expression <Func <TimeSpan, TimeSpan> >)(x => x),
            })
            {
                Assert.AreSame(e, cps.Visit(e));
            }

            foreach (var e in new Expression[]
            {
#pragma warning disable IDE0004 // Remove Unnecessary Cast. (Only unnecessary on C# 10 or later.)
                (Expression <Func <int, int> >)(x => x),
#pragma warning restore IDE0004
            })
            {
                Assert.ThrowsException <NotSupportedException>(() => cps.Visit(e));
            }
        }