private Expression GetEventAssignExpression(EventReferenceExpression target, Expression argument, string eventMethodPrefix, IEnumerable <Instruction> instructions)
 {
     if (String.op_Equality(eventMethodPrefix, "add_"))
     {
         return(new BinaryExpression(2, target, argument, this.typeSystem, instructions, false));
     }
     if (!String.op_Equality(eventMethodPrefix, "remove_"))
     {
         return(null);
     }
     return(new BinaryExpression(4, target, argument, this.typeSystem, instructions, false));
 }
예제 #2
0
 private Expression GetEventAssignExpression(EventReferenceExpression target, Expression argument, string eventMethodPrefix, IEnumerable <Instruction> instructions)
 {
     if (eventMethodPrefix == "add_")
     {
         return(new BinaryExpression(BinaryOperator.AddAssign, target, argument, typeSystem, instructions));
     }
     if (eventMethodPrefix == "remove_")
     {
         return(new BinaryExpression(BinaryOperator.SubtractAssign, target, argument, typeSystem, instructions));
     }
     return(null);
 }
        /// <summary>
        /// Create a <c>firedEvent(parameters)</c> invocation.</c>
        /// </summary>
        /// <param name="firedEvent">Delegate to invoke</param>
        /// <param name="parameters">Delegate arguments</param>
        /// <returns></returns>
        public static DelegateInvokeExpression DelegateInvoke(
            EventReferenceExpression firedEvent,
            params Expression[] parameters
            )
        {
            if (firedEvent == null)
            {
                throw new ArgumentNullException("firedEvent");
            }
            DelegateInvokeExpression expr = new DelegateInvokeExpression(firedEvent, parameters);

            return(expr);
        }
예제 #4
0
 public AttachRemoveEventStatement(EventReferenceExpression eventRef, Expression listener, bool attach)
 {
     if (eventRef == null)
     {
         throw new ArgumentNullException("eventRef");
     }
     if (listener == null)
     {
         throw new ArgumentNullException("listener");
     }
     this.eventRef = eventRef;
     this.listener = listener;
     this.attach   = attach;
 }
 public ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
 {
     if (node.get_MethodExpression() == null)
     {
         return(null);
     }
     V_0 = node.get_MethodExpression();
     V_1 = V_0.get_Method();
     if (V_1.get_Name() == null)
     {
         return(null);
     }
     V_2 = this.GetEventMethodPrefix(V_1.get_Name());
     if (String.IsNullOrEmpty(V_2))
     {
         return(null);
     }
     if (V_1.get_Parameters().get_Count() != 1)
     {
         return(null);
     }
     V_3 = V_1.get_DeclaringType();
     V_4 = null;
     do
     {
         V_6 = new RebuildEventsStep.u003cu003ec__DisplayClass2_0();
         if (V_3 == null)
         {
             break;
         }
         V_7 = V_3.Resolve();
         if (V_7 == null)
         {
             break;
         }
         V_6.eventName = V_1.get_Name().Substring(V_2.get_Length());
         V_4           = V_7.get_Events().FirstOrDefault <EventDefinition>(new Func <EventDefinition, bool>(V_6.u003cVisitMethodInvocationExpressionu003eb__0));
         if (V_4 != null)
         {
             continue;
         }
         V_3 = V_7.get_BaseType();
     }while (V_3 != null && V_4 == null);
     if (V_4 == null)
     {
         return(null);
     }
     V_5 = new EventReferenceExpression(V_0.get_Target(), V_4, null);
     return(this.GetEventAssignExpression(V_5, node.get_Arguments().get_Item(0), V_2, node.get_InvocationInstructions()));
 }
예제 #6
0
        public ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
        {
            if (!(node.MethodExpression is MethodReferenceExpression))
            {
                return(null);
            }

            MethodReferenceExpression methodReferenceExpression = node.MethodExpression;

            MethodReference methodReference = methodReferenceExpression.Method;

            if (methodReference.Name == null)
            {
                return(null);
            }

            string eventMethodPrefix = GetEventMethodPrefix(methodReference.Name);

            if (string.IsNullOrEmpty(eventMethodPrefix))
            {
                return(null);
            }

            if (methodReference.Parameters.Count != 1)
            {
                return(null);
            }

            TypeReference   typeReference = methodReference.DeclaringType;
            EventDefinition targetEvent   = null;

            do
            {
                if (typeReference == null)
                {
                    break;
                }

                TypeDefinition typeDefinition = typeReference.Resolve();

                if (typeDefinition == null)
                {
                    break;
                }

                string eventName = methodReference.Name.Substring(eventMethodPrefix.Length);
                targetEvent = typeDefinition.Events.FirstOrDefault(e => e.Name == eventName);
                if (targetEvent == null)
                {
                    typeReference = typeDefinition.BaseType;
                }
            } while (typeReference != null && targetEvent == null);

            if (targetEvent == null)
            {
                return(null);
            }

            EventReferenceExpression target = new EventReferenceExpression(methodReferenceExpression.Target, targetEvent, null);

            return(GetEventAssignExpression(target, node.Arguments[0], eventMethodPrefix, node.InvocationInstructions));
        }
예제 #7
0
 public virtual void VisitEventReferenceExpression(EventReferenceExpression node)
 {
     Visit(node.Target);
 }
예제 #8
0
 public virtual ICodeNode VisitEventReferenceExpression(EventReferenceExpression node)
 {
     node.Target = (Expression)Visit(node.Target);
     return(node);
 }
 public override ICodeNode VisitEventReferenceExpression(EventReferenceExpression node)
 {
     node.Target = (Expression)VisitTargetExpression(node.Target);
     return(node);
 }
예제 #10
0
 public virtual void VisitEventReferenceExpression(EventReferenceExpression node)
 {
     this.Visit(node.get_Target());
     return;
 }
 public override void VisitEventReferenceExpression(EventReferenceExpression node)
 {
     throw new Exception("Visual Basic does not support this type of event usage. Please, try using other language.");
 }
        private bool TryMatchInternal(StatementCollection statements, int startIndex, out Statement result)
        {
            result = null;

            if (startIndex + 1 >= statements.Count)
            {
                return(false);
            }

            if (statements[startIndex].CodeNodeType != CodeNodeType.ExpressionStatement ||
                statements[startIndex + 1].CodeNodeType != CodeNodeType.IfStatement)
            {
                return(false);
            }

            ExpressionStatement eventVariableAssignmentStatement = (statements[startIndex] as ExpressionStatement);

            if (eventVariableAssignmentStatement.Expression.CodeNodeType != CodeNodeType.BinaryExpression)
            {
                return(false);
            }

            BinaryExpression eventVariableAssignmentExpression = eventVariableAssignmentStatement.Expression as BinaryExpression;

            if (eventVariableAssignmentExpression.Left.CodeNodeType != CodeNodeType.VariableReferenceExpression ||
                eventVariableAssignmentExpression.Right.CodeNodeType != CodeNodeType.EventReferenceExpression)
            {
                return(false);
            }

            VariableReferenceExpression eventVariableDeclaration = eventVariableAssignmentExpression.Left as VariableReferenceExpression;
            EventReferenceExpression    eventReferenceExpression = eventVariableAssignmentExpression.Right as EventReferenceExpression;

            IfStatement theIf = statements[startIndex + 1] as IfStatement;

            if (theIf.Then == null ||
                theIf.Else != null ||
                theIf.Condition.CodeNodeType != CodeNodeType.BinaryExpression)
            {
                return(false);
            }

            BinaryExpression condition = theIf.Condition as BinaryExpression;

            if (condition.Left.CodeNodeType != CodeNodeType.VariableReferenceExpression ||
                condition.Right.CodeNodeType != CodeNodeType.LiteralExpression ||
                condition.Operator != BinaryOperator.ValueInequality)
            {
                return(false);
            }

            VariableReferenceExpression eventVariableReference = condition.Left as VariableReferenceExpression;

            if (eventVariableDeclaration.Variable != eventVariableReference.Variable)
            {
                return(false);
            }

            LiteralExpression theLiteral = condition.Right as LiteralExpression;

            if (theLiteral.Value != null)
            {
                return(false);
            }

            StatementCollection thenStatements = theIf.Then.Statements;

            if (thenStatements.Count != 1 ||
                thenStatements[0].CodeNodeType != CodeNodeType.ExpressionStatement)
            {
                return(false);
            }

            ExpressionStatement delegateInvocationStatement = thenStatements[0] as ExpressionStatement;

            if (delegateInvocationStatement.Expression.CodeNodeType != CodeNodeType.DelegateInvokeExpression)
            {
                return(false);
            }

            DelegateInvokeExpression delegateInvocationExpression = delegateInvocationStatement.Expression as DelegateInvokeExpression;

            if (delegateInvocationExpression.Target.CodeNodeType != CodeNodeType.VariableReferenceExpression)
            {
                return(false);
            }

            VariableReferenceExpression delegateInvocationVariableReferece = delegateInvocationExpression.Target as VariableReferenceExpression;

            if (delegateInvocationVariableReferece.Variable != eventVariableDeclaration.Variable)
            {
                return(false);
            }

            List <Instruction> instructions = new List <Instruction>();

            instructions.AddRange(eventVariableAssignmentStatement.UnderlyingSameMethodInstructions);
            instructions.AddRange(theIf.UnderlyingSameMethodInstructions);

            result = new ExpressionStatement(new RaiseEventExpression(eventReferenceExpression.Event, delegateInvocationExpression.InvokeMethodReference, delegateInvocationExpression.Arguments, instructions));

            return(true);
        }
예제 #13
0
 public override ICodeNode VisitEventReferenceExpression(EventReferenceExpression node)
 {
     node.set_Target((Expression)this.VisitTargetExpression(node.get_Target()));
     return(node);
 }
 public virtual ICodeNode VisitEventReferenceExpression(EventReferenceExpression node)
 {
     node.set_Target((Expression)this.Visit(node.get_Target()));
     return(node);
 }
예제 #15
0
 public static AttachRemoveEventStatement Remove(
     EventReferenceExpression eventRef,
     Expression listener)
 {
     return(new AttachRemoveEventStatement(eventRef, listener, false));
 }