private Expression WithEventCheck(GetMemberDynamicCSharpExpression member, string accessor)
        {
            var obj  = member.Object;
            var name = member.Name;
            var args = member.Arguments;

            Debug.Assert(args.Count == 0);

            var lhs  = Expression.Parameter(obj.Type, "__objTemp");
            var left = Left.Update(member.Update(lhs, args));

            var isEventBinder = Binder.IsEvent(CSharpBinderFlags.None, name, Context);
            var isEventCheck  = DynamicHelpers.MakeDynamic(typeof(bool), isEventBinder, new[] { lhs }, null);

            var accessorName = accessor + name;
            var accessorArgs = new[]
            {
                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
            };

            var invokeAccessorBinder = Binder.InvokeMember(CSharpBinderFlags.InvokeSpecialName | CSharpBinderFlags.ResultDiscarded, accessorName, null, Context, accessorArgs);
            var invokeAccessor       = DynamicHelpers.MakeDynamic(typeof(object), invokeAccessorBinder, new[] { lhs, Right.Expression }, null);

            var ifNotEvent = ReduceCore(left);

            var res =
                Expression.Block(
                    new[] { lhs },
                    Expression.Assign(lhs, obj),
                    Expression.Condition(isEventCheck, invokeAccessor, ifNotEvent)
                    );

            return(res);
        }
Exemplo n.º 2
0
        private static Expression ReduceDynamicMember(GetMemberDynamicCSharpExpression member, Func <Expression, Expression> functionalOp, CSharpBinderFlags flags, bool prefix)
        {
            var args  = default(DynamicCSharpArgument[]);
            var block = default(Expression[]);
            var temps = default(ParameterExpression[]);
            var i     = CopyArguments(member.Object, member.Arguments, prefix, out args, out block, out temps);

            member = member.Update(temps[0], new TrueReadOnlyCollection <DynamicCSharpArgument>(args));

            if (prefix)
            {
                block[i++] = member.ReduceAssignment(functionalOp(member), flags);
            }
            else
            {
                var lastTemp = temps[i] = Expression.Parameter(member.Type, "__temp");

                block[i] = Expression.Assign(temps[i], member);
                i++;

                block[i++] = member.ReduceAssignment(functionalOp(lastTemp), flags);
                block[i++] = lastTemp;
            }

            var res = Expression.Block(temps, block);

            return(res);
        }
Exemplo n.º 3
0
        private static Expression ReduceDynamicMember(GetMemberDynamicCSharpExpression member, Func<Expression, Expression> functionalOp, CSharpBinderFlags flags, bool prefix)
        {
            var args = default(DynamicCSharpArgument[]);
            var block = default(Expression[]);
            var temps = default(ParameterExpression[]);
            var i = CopyArguments(member.Object, member.Arguments, prefix, out args, out block, out temps);

            member = member.Update(temps[0], new TrueReadOnlyCollection<DynamicCSharpArgument>(args));

            if (prefix)
            {
                block[i++] = member.ReduceAssignment(functionalOp(member), flags);
            }
            else
            {
                var lastTemp = temps[i] = Expression.Parameter(member.Type, "__temp");

                block[i] = Expression.Assign(temps[i], member);
                i++;

                block[i++] = member.ReduceAssignment(functionalOp(lastTemp), flags);
                block[i++] = lastTemp;
            }

            var res = Expression.Block(temps, block);
            return res;
        }
Exemplo n.º 4
0
        private Expression ReduceAssign()
        {
            var lhs = Left.Expression;

            return(lhs switch
            {
                GetMemberDynamicCSharpExpression getMember => getMember.ReduceAssignment(Right.Expression, Flags, Left.Flags, Right.Flags),
                GetIndexDynamicCSharpExpression getIndex => getIndex.ReduceAssignment(Right.Expression, Flags, Left.Flags, Right.Flags),
                _ => ReduceStaticAssign(),
            });
Exemplo n.º 5
0
        public static Expression ReduceDynamicAssignment(DynamicCSharpArgument left, Func <Expression, Expression> functionalOp, CSharpBinderFlags flags, bool prefix = true)
        {
            var lhs = MakeWriteable(left.Expression);

            return(lhs switch
            {
                GetMemberDynamicCSharpExpression dynamicMember => ReduceDynamicMember(dynamicMember, functionalOp, flags, prefix),
                GetIndexDynamicCSharpExpression dynamicIndex => ReduceDynamicIndex(dynamicIndex, functionalOp, flags, prefix),
                _ => Helpers.ReduceAssignment(lhs, functionalOp, prefix),
            });
Exemplo n.º 6
0
        protected internal override Expression VisitDynamicGetMember(GetMemberDynamicCSharpExpression node)
        {
            var args = new List <object>();

            args.Add(new XAttribute(nameof(node.Name), node.Name));

            VisitDynamicCSharpExpression(node, args);

            args.Add(new XElement(nameof(node.Object), Visit(node.Object)));

            return(Push(node, args));
        }
 private static Expression ReduceDynamicMember(GetMemberDynamicCSharpExpression member, Func <Expression, Expression> functionalOp, CSharpBinderFlags flags, bool prefix)
 {
     var i = CopyArguments(member.Object, member.Arguments, prefix, out DynamicCSharpArgument[] args, out Expression[] block, out ParameterExpression[] temps);
 public GetMemberDynamicCSharpExpressionProxy(GetMemberDynamicCSharpExpression node)
 {
     _node = node;
 }
        private Expression WithEventCheck(GetMemberDynamicCSharpExpression member, string accessor)
        {
            var obj = member.Object;
            var name = member.Name;
            var args = member.Arguments;

            Debug.Assert(args.Count == 0);

            var lhs = Expression.Parameter(obj.Type, "__objTemp");
            var left = Left.Update(member.Update(lhs, args));

            var isEventBinder = Binder.IsEvent(CSharpBinderFlags.None, name, Context);
            var isEventCheck = DynamicHelpers.MakeDynamic(typeof(bool), isEventBinder, new[] { lhs }, null);

            var accessorName = accessor + name;
            var accessorArgs = new[]
            {
                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
            };

            var invokeAccessorBinder = Binder.InvokeMember(CSharpBinderFlags.InvokeSpecialName | CSharpBinderFlags.ResultDiscarded, accessorName, null, Context, accessorArgs);
            var invokeAccessor = DynamicHelpers.MakeDynamic(typeof(object), invokeAccessorBinder, new[] { lhs, Right.Expression }, null);

            var ifNotEvent = ReduceCore(left);

            var res =
                Expression.Block(
                    new[] { lhs },
                    Expression.Assign(lhs, obj),
                    Expression.Condition(isEventCheck, invokeAccessor, ifNotEvent)
                );

            return res;
        }
 protected internal virtual Expression VisitDynamicGetMember(GetMemberDynamicCSharpExpression node)
 {
     return(node.Update(Visit(node.Object), Visit(node.Arguments, VisitDynamicArgument)));
 }
 public GetMemberDynamicCSharpExpressionProxy(GetMemberDynamicCSharpExpression node)
 {
     _node = node;
 }
 protected internal virtual Expression VisitDynamicGetMember(GetMemberDynamicCSharpExpression node)
 {
     return node.Update(Visit(node.Object), Visit(node.Arguments, VisitDynamicArgument));
 }