public void ExpressionMemberAllowListScannerBase_SomePass()
        {
            var aps = new SomePassScanner();

            foreach (var e in new Expression[] {
                (Expression <Func <int, int> >)(x => - x),
                (Expression <Func <int, int, int> >)((a, b) => a + b),
                (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 <Bar> >)(() => new Bar {
                    Foo = 1
                }),
            })
            {
                Assert.AreSame(e, aps.Visit(e));
            }

            foreach (var e in new Expression[] {
                (Expression <Func <TimeSpan, TimeSpan> >)(t => - t),
                (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));
            }
        }
Ejemplo n.º 2
0
        public void ExpressionTypeAllowListScannerBase_SomePass()
        {
            var aps = new SomePassScanner();

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

            foreach (var e in new Expression[] {
                (Expression <Func <Process> >)(() => Process.Start("notepad.exe")),
                (Expression <Func <FileStream> >)(() => File.OpenRead("foo.txt")),
                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));
            }
        }