private Expression GenerateInvokeMemeberExpression(CallSiteInfo callSiteInfo, IList <Expression> arguments, IEnumerable <Instruction> instructions) { if (arguments.Count < 1) { throw new Exception("Invalid number of arguments for invoke expression."); } Expression target; TypeReference typeRef; if (arguments[0].CodeNodeType == CodeNodeType.MethodInvocationExpression && (arguments[0] as MethodInvocationExpression).IsTypeOfExpression(out typeRef)) { target = new TypeReferenceExpression(typeRef, arguments[0].UnderlyingSameMethodInstructions); } else { target = arguments[0]; } DynamicMemberReferenceExpression dynamicMemberReferenceExpression = new DynamicMemberReferenceExpression(target, callSiteInfo.MemberName, objectTypeRef, instructions, GetAllButFirst(arguments), callSiteInfo.GenericTypeArguments); return(dynamicMemberReferenceExpression); }
public virtual void VisitDynamicMemberReferenceExpression(DynamicMemberReferenceExpression node) { Visit(node.Target); if (node.IsMethodInvocation) { Visit(node.InvocationArguments); } }
public virtual ICodeNode VisitDynamicMemberReferenceExpression(DynamicMemberReferenceExpression node) { node.Target = (Expression)Visit(node.Target); if (node.IsMethodInvocation) { node.InvocationArguments = (ExpressionCollection)Visit(node.InvocationArguments); } return(node); }
public virtual void VisitDynamicMemberReferenceExpression(DynamicMemberReferenceExpression node) { this.Visit(node.get_Target()); if (node.get_IsMethodInvocation()) { this.Visit(node.get_InvocationArguments()); } return; }
public virtual ICodeNode VisitDynamicMemberReferenceExpression(DynamicMemberReferenceExpression node) { node.set_Target((Expression)this.Visit(node.get_Target())); if (node.get_IsMethodInvocation()) { node.set_InvocationArguments((ExpressionCollection)this.Visit(node.get_InvocationArguments())); } return(node); }
private void ReplaceIfWith(IfStatement theIf, BlockStatement statementBlock) { if (!CanReplaceIf(statementBlock)) { throw new Exception(InvalidIsEventString); } DynamicMemberReferenceExpression dynamicMethodInvocation = (statementBlock.Statements[1] as ExpressionStatement).Expression as DynamicMemberReferenceExpression; if (dynamicMethodInvocation == null) // the expression was an assignment { dynamicMethodInvocation = ((statementBlock.Statements[1] as ExpressionStatement).Expression as BinaryExpression).Right as DynamicMemberReferenceExpression; } if (dynamicMethodInvocation.MemberName == null || !dynamicMethodInvocation.IsMethodInvocation || dynamicMethodInvocation.IsGenericMethod || dynamicMethodInvocation.InvocationArguments.Count != 1) { throw new Exception(InvalidIsEventString); } int charIndex = dynamicMethodInvocation.MemberName.IndexOf('_'); if (charIndex != 3 && charIndex != 6) //"add_" - 3, "remove_" - 6 { throw new Exception(InvalidIsEventString); } DynamicMemberReferenceExpression dynamicMemberRef = new DynamicMemberReferenceExpression(dynamicMethodInvocation.Target, dynamicMethodInvocation.MemberName.Substring(charIndex + 1), dynamicMethodInvocation.ExpressionType, dynamicMethodInvocation.MappedInstructions); BinaryExpression theBinaryExpression = new BinaryExpression(charIndex == 3 ? BinaryOperator.AddAssign : BinaryOperator.SubtractAssign, dynamicMemberRef, dynamicMethodInvocation.InvocationArguments[0], dynamicMemberRef.ExpressionType, typeSystem, null); BlockStatement parent = (BlockStatement)theIf.Parent; int ifIndex = parent.Statements.IndexOf(theIf); ExpressionStatement theAssignStatement = new ExpressionStatement(theBinaryExpression); theAssignStatement.Parent = parent; parent.Statements[ifIndex] = theAssignStatement; if (statementBlock.Statements.Count == 3) { parent.AddStatementAt(ifIndex + 1, statementBlock.Statements[2].Clone()); } }
private void ReplaceIfWith(IfStatement theIf, BlockStatement statementBlock) { if (!this.CanReplaceIf(statementBlock)) { throw new Exception("Invalid IsEvent construction"); } V_0 = (statementBlock.get_Statements().get_Item(1) as ExpressionStatement).get_Expression() as DynamicMemberReferenceExpression; if (V_0 == null) { V_0 = ((statementBlock.get_Statements().get_Item(1) as ExpressionStatement).get_Expression() as BinaryExpression).get_Right() as DynamicMemberReferenceExpression; } if (V_0.get_MemberName() == null || !V_0.get_IsMethodInvocation() || V_0.get_IsGenericMethod() || V_0.get_InvocationArguments().get_Count() != 1) { throw new Exception("Invalid IsEvent construction"); } V_1 = V_0.get_MemberName().IndexOf('\u005F'); if (V_1 != 3 && V_1 != 6) { throw new Exception("Invalid IsEvent construction"); } V_2 = new DynamicMemberReferenceExpression(V_0.get_Target(), V_0.get_MemberName().Substring(V_1 + 1), V_0.get_ExpressionType(), V_0.get_MappedInstructions()); if (V_1 == 3) { stackVariable44 = 2; } else { stackVariable44 = 4; } stackVariable56 = new BinaryExpression(stackVariable44, V_2, V_0.get_InvocationArguments().get_Item(0), V_2.get_ExpressionType(), this.typeSystem, null, false); V_3 = (BlockStatement)theIf.get_Parent(); V_4 = V_3.get_Statements().IndexOf(theIf); V_5 = new ExpressionStatement(stackVariable56); V_5.set_Parent(V_3); V_3.get_Statements().set_Item(V_4, V_5); if (statementBlock.get_Statements().get_Count() == 3) { V_3.AddStatementAt(V_4 + 1, statementBlock.get_Statements().get_Item(2).Clone()); } return; }