Пример #1
0
        // If the DynamicExpression uses a transient (in-memory) type for its
        // delegate, we need to replace it with a new delegate type that can be
        // saved to disk
        protected override Expression VisitDynamic(DynamicExpression node)
        {
            if (RewriteDelegate(node.DelegateType, out Type delegateType))
            {
                node = DynamicExpression.MakeDynamic(delegateType, node.Binder, node.Arguments);
            }

            // Reduce dynamic expression so that the lambda can be emitted as a non-dynamic method.
            return(Visit(CompilerHelpers.Reduce(node)));
        }
Пример #2
0
            protected override Expression VisitDynamic(DynamicExpression node)
            {
                CallSiteBinder binder = node.Binder;

                if (!(binder is InterceptorSiteBinder))
                {
                    binder = new InterceptorSiteBinder(binder);
                    return(DynamicExpression.MakeDynamic(node.DelegateType, binder, node.Arguments));
                }

                return(node);
            }
Пример #3
0
        protected override Expression VisitDynamic(DynamicExpression node)
        {
            int yields = _yields.Count;
            ReadOnlyCollection <Expression> a = Visit(node.Arguments);

            if (a == node.Arguments)
            {
                return(node);
            }
            if (yields == _yields.Count)
            {
                return(DynamicExpression.MakeDynamic(node.DelegateType, node.Binder, a));
            }
            return(Expression.Block(
                       ToTemp(ref a),
                       DynamicExpression.MakeDynamic(node.DelegateType, node.Binder, a)
                       ));
        }
Пример #4
0
        public void TypedAritySpecialisedUsedWhenPossible(int size, string nameSuffix)
        {
            CallSiteBinder binder = Binder.GetMember(
                CSharpBinderFlags.None, "Member", GetType(),
                new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });
            Type delType = Expression.GetFuncType(
                Enumerable.Repeat(typeof(object), size).Append(typeof(string)).Prepend(typeof(CallSite)).ToArray());
            DynamicExpression exp = DynamicExpression.MakeDynamic(
                delType, binder, Enumerable.Range(0, size).Select(_ => Expression.Constant(null)));

            Assert.Equal("TypedDynamicExpression" + nameSuffix, exp.GetType().Name);
            exp = Expression.MakeDynamic(
                delType, binder, Enumerable.Range(0, size).Select(_ => Expression.Constant(null)));
            Assert.Equal("TypedDynamicExpression" + nameSuffix, exp.GetType().Name);
            if (size != 0)
            {
                exp = Expression.Dynamic(
                    binder, typeof(string), Enumerable.Range(0, size).Select(_ => Expression.Constant(null)));
                Assert.Equal("TypedDynamicExpression" + nameSuffix, exp.GetType().Name);
            }
        }