public override ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
        {
            node.MethodExpression = (MethodReferenceExpression)Visit(node.MethodExpression);
            if (status != InliningResult.NotFound)
            {
                return node;
            }

            MethodReference methodRef = node.MethodExpression.Method;

            for (int i = 0; i < node.Arguments.Count; i++)
            {
                if (!methodRef.Parameters[i].ParameterType.IsByReference)
                {
                    node.Arguments[i] = (Expression)Visit(node.Arguments[i]);

                    if (status != InliningResult.NotFound)
                    {
                        return node;
                    }
                }
                else if (valueHasSideEffects)
                {
                    SideEffectsFinder sideEffectsFinder = new SideEffectsFinder();
                    if (sideEffectsFinder.HasSideEffectsRecursive(node.Arguments[i]))
                    {
                        status = InliningResult.Abort;
                        return node;
                    }
                }
            }

            return node;
        }
        public override ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
        {
            Expression methodTarget = node.GetTarget();
            if (methodTarget != null)
            {
                if (methodTarget.CodeNodeType == CodeNodeType.VariableReferenceExpression)
                {
                    VariableReference variable = (methodTarget as VariableReferenceExpression).Variable;
                    if (this.variableToReplacingExpressionMap.ContainsKey(variable))
                    {
                        this.variablesToNotInline.Add(variable);
                    }
                }
                else if (methodTarget.CodeNodeType == CodeNodeType.FieldReferenceExpression)
                {
                    FieldDefinition field = (methodTarget as FieldReferenceExpression).Field.Resolve();
                    if (this.fieldToReplacingExpressionMap.ContainsKey(field))
                    {
                        VariableReference variableToNotInline = (this.fieldToReplacingExpressionMap[field] as VariableReferenceExpression).Variable;
                        this.variablesToNotInline.Add(variableToNotInline);
                    }
                }
            }

            return base.VisitMethodInvocationExpression(node);
        }
		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);
		}
        public override ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
        {
            base.VisitMethodInvocationExpression(node);

            FixArguments(node.MethodExpression.Method, node.Arguments);

            return node;
        }
		public override void VisitMethodInvocationExpression(MethodInvocationExpression node)
		{
			base.VisitMethodInvocationExpression(node);
			if (node.MethodExpression.CodeNodeType == CodeNodeType.MethodReferenceExpression)
			{
				FixArguments(node.MethodExpression.Method, node.Arguments);
			}
		}
 public MethodSpecificContext(MethodBody body,
     Dictionary<VariableDefinition, string> variableDefinitionToNameMap, Dictionary<ParameterDefinition, string> parameterDefinitionTonameMap,
     MethodInvocationExpression ctorInvokeExpression)
     : this(body)
 {
     this.VariableDefinitionToNameMap = variableDefinitionToNameMap;
     this.ParameterDefinitionToNameMap = parameterDefinitionTonameMap;
     this.CtorInvokeExpression = ctorInvokeExpression;
 }
 public override ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
 {
     LinqQueryExpression result;
     if (TryMatchLinqQuery(node, out result))
     {
         return RemoveTransparentIdentifiers(result);
     }
     return base.VisitMethodInvocationExpression(node);
 }
        public ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
        {
            MethodReferenceExpression methodReference = node.MethodExpression;
            if ((methodReference == null) ||
                (methodReference.Method.CallingConvention == MethodCallingConvention.StdCall))
            {
                return null;
            }

			MethodReference method = methodReference.Method;

			BinaryOperator binaryOperator;
            if (binaryOperators.TryGetValue (method.Name, out binaryOperator))
            {
                return BuildBinaryExpression(binaryOperator, node.Arguments[0], node.Arguments[1], method.FixedReturnType, node.InvocationInstructions);
            }

			UnaryOperator unaryOperator;
            if (unaryOperators.TryGetValue (method.Name, out unaryOperator))
            {
                return BuildUnaryExpression(unaryOperator, node.Arguments[0], node.InvocationInstructions);
            }
			
            if(method.Name == "op_True")
            {
                return (Expression)codeTransformer.Visit(node.Arguments[0]);
            }
            else if(method.Name == "op_False")
            {
                //TODO: Must consider better representation
                return new ConditionExpression((Expression)codeTransformer.Visit(node.Arguments[0]),
                        new LiteralExpression(false, typeSystem, null), new LiteralExpression(true, typeSystem, null), node.InvocationInstructions);
            }

            if (method.Name == "op_Explicit")
            {
                return new CastExpression((Expression)codeTransformer.Visit(node.Arguments[0]), node.ExpressionType, node.InvocationInstructions);
            }

            if (method.Name == "op_Implicit")
            { 
                return codeTransformer.Visit(node.Arguments[0]);
            }

            if (method.Name == "get_Chars" && node.MethodExpression.Target.ExpressionType.FullName == "System.String")
            {
                ArrayIndexerExpression stringIndexing = new ArrayIndexerExpression(node.MethodExpression.Target, node.InvocationInstructions);
                foreach (Expression arg in node.Arguments)
                {
                    stringIndexing.Indices.Add(arg);
                }
                return stringIndexing;
            }

			return null;
		}
Exemplo n.º 9
0
        public ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
        {
            TypeReference typeReference;
            if (!node.IsTypeOfExpression(out typeReference))
            {
                return null;
            }

			return new TypeOfExpression (typeReference, node.UnderlyingSameMethodInstructions);
		}
        public override ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
        {
			ICodeNode newNode = typeOfStep.VisitMethodInvocationExpression(node);
			if (newNode != null)
			{
				return newNode;
			}
			replaceThisWithBaseStep.VisitMethodInvocationExpression(node);

			newNode = operatorStep.VisitMethodInvocationExpression(node);

			if (newNode != null)
			{
				return base.Visit(newNode);
			}

			newNode = replaceDelegateInvokeStep.VisitMethodInvocationExpression(node);

			if (newNode != null)
			{
				return base.VisitDelegateInvokeExpression(newNode as DelegateInvokeExpression);
			}
			newNode = propertyRecognizer.VisitMethodInvocationExpression(node);

            if (newNode != null)
            {
                PropertyReferenceExpression propertyReference = newNode as PropertyReferenceExpression;

                if (propertyReference != null) // if it was a getter
                {
                    newNode = this.VisitPropertyReferenceExpression(propertyReference);
                }
				if (newNode is BinaryExpression) // if it was a setter
				{
					newNode = this.VisitBinaryExpression(newNode as BinaryExpression);
				}
                return newNode;
            }

			newNode = rebuildEventsStep.VisitMethodInvocationExpression(node);

			if (newNode != null)
			{
				if (newNode is BinaryExpression)
				{
					return VisitBinaryExpression(newNode as BinaryExpression);
				}
				return newNode;
			}
			return base.VisitMethodInvocationExpression(node);
		}
        public ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
        {
			if (node.MethodExpression.CodeNodeType == CodeNodeType.MethodReferenceExpression)
			{
                MethodReferenceExpression methodReferenceExpression = node.MethodExpression;
				MethodReference methodReference = methodReferenceExpression.Method;
				if (IsDelegateInvokeMethod(methodReference))
				{
                    ExpressionCollection visitedArguments = (ExpressionCollection)codeTransformer.Visit(node.Arguments);
					return new DelegateInvokeExpression(methodReferenceExpression.Target, visitedArguments, methodReference, node.InvocationInstructions);
				}
			}
			return null;
		}
			public override void VisitMethodInvocationExpression(MethodInvocationExpression node)
			{
				Visit(node.MethodExpression);

				if (node.MethodExpression is MethodReferenceExpression)
				{
					this.methodInvocationsStackCount++;
				}

				Visit(node.Arguments);

				if (node.MethodExpression is MethodReferenceExpression)
				{
					this.methodInvocationsStackCount--;
				}
			}
 internal MethodSpecificContext(DecompilationAnalysisResults analysisResults, YieldData yieldData, AsyncData asyncData,
     bool isMethodBodyChanged, Dictionary<string, Statement> gotoLabels, List<GotoStatement> gotoStatements,
     StackUsageData stackData, bool isBaseConstructorInvokingConstructor, bool enableEventAnalysis,
     MethodBody body, Collection<VariableDefinition> variables, ControlFlowGraph controlFlowGraph,
     ExpressionDecompilerData expressions, BlockLogicalConstruct logicalConstructsTree, LogicalFlowBuilderContext logicalConstructsContext,
     MethodInvocationExpression ctorInvokeExpression, Dictionary<Statement, ILogicalConstruct> statementToLogicalConstruct,
     Dictionary<ILogicalConstruct, List<Statement>> logicalConstructToStatements, Dictionary<VariableDefinition, string> variableDefinitionToNameMap,
     HashSet<string> variableNamesCollection, Dictionary<ParameterDefinition, string> parameterDefinitionToNameMap,
     HashSet<VariableDefinition> variablesToRename, Dictionary<FieldDefinition, Expression> fieldToExpression,
     int lambdaVariablesCount, Dictionary<VariableDefinition, AssignmentType> variableAssignmentData, List<ParameterDefinition> outParametersToAssign,
     bool isDestructor, BlockStatement destructorStatements, HashSet<VariableDefinition> undeclaredLinqVariables,
     Dictionary<VariableReference, Dictionary<FieldDefinition, Expression>> closureVariableToFieldValue,
     HashSet<VariableDefinition> variablesToNotDeclare)
 {
     this.AnalysisResults = analysisResults;
     this.YieldData = yieldData;
     this.AsyncData = asyncData;
     this.IsMethodBodyChanged = isMethodBodyChanged;
     this.GotoLabels = gotoLabels;
     this.GotoStatements = gotoStatements;
     this.StackData = stackData;
     this.IsBaseConstructorInvokingConstructor = isBaseConstructorInvokingConstructor;
     this.EnableEventAnalysis = enableEventAnalysis;
     this.Body = body;
     this.Variables = variables;
     this.ControlFlowGraph = controlFlowGraph;
     this.Expressions = expressions;
     this.LogicalConstructsTree = logicalConstructsTree;
     this.LogicalConstructsContext = logicalConstructsContext;
     this.CtorInvokeExpression = ctorInvokeExpression;
     this.StatementToLogicalConstruct = statementToLogicalConstruct;
     this.LogicalConstructToStatements = logicalConstructToStatements;
     this.VariableDefinitionToNameMap = variableDefinitionToNameMap;
     this.VariableNamesCollection = variableNamesCollection;
     this.ParameterDefinitionToNameMap = parameterDefinitionToNameMap;
     this.VariablesToRename = variablesToRename;
     this.FieldToExpression = fieldToExpression;
     this.LambdaVariablesCount = lambdaVariablesCount;
     this.VariableAssignmentData = variableAssignmentData;
     this.OutParametersToAssign = outParametersToAssign;
     this.IsDestructor = isDestructor;
     this.DestructorStatements = destructorStatements;
     this.UndeclaredLinqVariables = undeclaredLinqVariables;
     this.ClosureVariableToFieldValue = closureVariableToFieldValue;
     this.VariablesToNotDeclare = variablesToNotDeclare;
 }
        public ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
        {
            MethodReferenceExpression methodRef = node.MethodExpression;

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

            MethodDefinition method = methodRef.Method as MethodDefinition;

            //// must be resolved.
            if (method == null)
            {
                MethodReference methodReference = methodRef.Method;
                if (methodReference != null
                    && !string.IsNullOrEmpty(methodReference.Name)
                    && (methodReference.Name.StartsWith("set_") || methodReference.Name.StartsWith("get_") || methodReference.Name.StartsWith("put_") /*Setter prefix in winrt*/))
                {
                    method = methodReference.Resolve();
                }
            }

            if (method != null)
            {
                if (method.IsGetter || method.IsSetter)
                {
                    PropertyReferenceExpression propExpr = new PropertyReferenceExpression(node, null);
                    if (propExpr.Property == null)
                    {
                        // sanity check - if the method is resolved and is determined to be getter/setter, then a
                        // property record should be available.
                        return node;
                    }
                    Expression result = propExpr;
                    if (method.IsSetter)
                    {
                        int last = node.Arguments.Count - 1;
                        result = new BinaryExpression(BinaryOperator.Assign, propExpr, node.Arguments[last], typeSystem, null);
                    }
                    return result;
                }
            }
            return null;
        }
 public override ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
 {
     Expression visitedExpression = (Expression)base.VisitMethodInvocationExpression(node);
     MethodInvocationExpression methodInvocation = visitedExpression as MethodInvocationExpression;
     if (methodInvocation != null && methodInvocation.MethodExpression.Target != null && methodInvocation.MethodExpression.Method.Name == "Invoke")
     {
         if (methodInvocation.MethodExpression.Target.CodeNodeType == CodeNodeType.FieldReferenceExpression &&
             (methodInvocation.MethodExpression.Target as FieldReferenceExpression).Field.Name == "Target" &&
             (methodInvocation.MethodExpression.Target as FieldReferenceExpression).Target != null &&
             (methodInvocation.MethodExpression.Target as FieldReferenceExpression).Target.CodeNodeType == CodeNodeType.FieldReferenceExpression)
         {
             FieldDefinition fieldDef = ((methodInvocation.MethodExpression.Target as FieldReferenceExpression).Target as FieldReferenceExpression).Field.Resolve();
             CallSiteInfo callSiteInfo;
             if (fieldDef != null && fieldToCallSiteInfoMap.TryGetValue(fieldDef, out callSiteInfo))
             {
                 if (callSiteInfo.BinderType != CallSiteBinderType.IsEvent)
                 {
                     return GenerateExpression(callSiteInfo, methodInvocation.Arguments, methodInvocation.InvocationInstructions);
                 }
                 else
                 {
                     isEventIfStatements.Add(closestIf, methodInvocation);
                 }
             }
         }
         else if (methodInvocation.MethodExpression.Target.CodeNodeType == CodeNodeType.VariableReferenceExpression)
         {
             VariableReference varRef = (methodInvocation.MethodExpression.Target as VariableReferenceExpression).Variable;
             CallSiteInfo callSiteInfo;
             if (variableToCallSiteInfoMap.TryGetValue(varRef, out callSiteInfo))
             {
                 if (callSiteInfo.BinderType != CallSiteBinderType.IsEvent)
                 {
                     return GenerateExpression(callSiteInfo, methodInvocation.Arguments, methodInvocation.InvocationInstructions);
                 }
                 else
                 {
                     isEventIfStatements.Add(closestIf, methodInvocation);
                 }
             }
         }
     }
     return visitedExpression;
 }
Exemplo n.º 16
0
        public override ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
        {
            node = (MethodInvocationExpression)base.VisitMethodInvocationExpression(node);

            VisitInvocationArguments(node.Arguments, node.MethodExpression.Method);

            if (node.IsConstrained)
            {
                if (node.MethodExpression.Target.CodeNodeType == CodeNodeType.LiteralExpression)
                {
                    TypeDefinition constraintTypeDef = node.ConstraintType.Resolve();
                    if (constraintTypeDef.IsEnum)
                    {
                        node.MethodExpression.Target = EnumHelper.GetEnumExpression(constraintTypeDef, node.MethodExpression.Target as LiteralExpression, typeSystem);
                    }
                }
            }

            return node;
        }
            private bool TryMatchLinqQuery(MethodInvocationExpression methodInvocation, out LinqQueryExpression linqQuery)
            {
                Stack<MethodInvocationExpression> queryStack = new Stack<MethodInvocationExpression>();
                MethodInvocationExpression current = methodInvocation;
                bool isQueryableMethod = current.MethodExpression.MethodDefinition.IsQueryableMethod();
                while (current != null && current.MethodExpression.MethodDefinition.IsQueryMethod() && isQueryableMethod == current.MethodExpression.MethodDefinition.IsQueryableMethod())
                {
                    queryStack.Push(current);
                    current = current.Arguments[0] as MethodInvocationExpression;
                }

                if (queryStack.Count == 0)
                {
                    linqQuery = null;
                    return false;
                }

                MethodInvocationExpression top = queryStack.Peek();
                top.Arguments[0] = (Expression)Visit(top.Arguments[0]);
                linqQuery = ProcessExtensionMethodChain(queryStack, methodInvocation, isQueryableMethod);
                return linqQuery != null;
            }
        private Expression GetMethodHandleExpression(MethodReference methodReference, IEnumerable<Instruction> instructions)
        {
            TypeDefinition corlibTypeTypeDefinition = GetSystemTypeTypeDefinition();

            string[] parametersNames = methodReference.HasParameters ? new string[] { "System.String", "System.Type[]" } : new string[] { "System.String" };
            MethodReference getMethodReference = GetSystemTypeMethodReference(corlibTypeTypeDefinition, "GetMethod", parametersNames);

            MethodReference getMethodHandleReference = GetHandlePropertyGetterReference(typeof(System.Reflection.MethodBase), "get_MethodHandle");

            TypeOfExpression typeOfExpression = new TypeOfExpression(methodReference.DeclaringType, null);
            MethodReferenceExpression getMethodMethodReferenceExpression = new MethodReferenceExpression(typeOfExpression, getMethodReference, null);
            MethodInvocationExpression getMethodMethodInvocationExpression = new MethodInvocationExpression(getMethodMethodReferenceExpression, null);
            LiteralExpression argument = new LiteralExpression(methodReference.Name, this.typeSystem, null);
            getMethodMethodInvocationExpression.Arguments.Add(argument);

            if (methodReference.HasParameters)
            {
                BlockExpression blockExpression = new BlockExpression(null);
                foreach (ParameterDefinition parameter in methodReference.Parameters)
                {
                    blockExpression.Expressions.Add(new TypeOfExpression(parameter.ParameterType, null));
                }

				InitializerExpression initializer = new InitializerExpression(blockExpression, InitializerType.ArrayInitializer);
				ArrayCreationExpression getMethodTypeParametersArray = new ArrayCreationExpression(corlibTypeTypeDefinition, initializer, null);
                getMethodTypeParametersArray.Dimensions.Add(new LiteralExpression(blockExpression.Expressions.Count, this.typeSystem, null));

                getMethodMethodInvocationExpression.Arguments.Add(getMethodTypeParametersArray);
            }

            MethodReferenceExpression getMethodHandleMethodReferenceExpression = new MethodReferenceExpression(getMethodMethodInvocationExpression, getMethodHandleReference, null);
            MethodInvocationExpression getMethodHandleMethodInvocationExpression = new MethodInvocationExpression(getMethodHandleMethodReferenceExpression, instructions);
            PropertyReferenceExpression methodHandlePropertyReferenceExpression = new PropertyReferenceExpression(getMethodHandleMethodInvocationExpression, null);

            return methodHandlePropertyReferenceExpression;
        }
 public override void VisitMethodInvocationExpression(MethodInvocationExpression node)
 {
     if (IsGetCurrent(node))
     {
         ResultingType = node.ExpressionType;
     }
     base.VisitMethodInvocationExpression(node);
 }
 private bool IsMoveNextCall(MethodInvocationExpression invocation)
 {
     if (invocation == null)
     {
         return false;
     }
     if (invocation.MethodExpression.Method.Name == "MoveNext")
     {
         VariableReferenceExpression target = invocation.MethodExpression.Target as VariableReferenceExpression;
         if (target != null)
         {
             if (target.Variable == theEnumerator)
             {
                 return true;
             }
         }
     }
     return false;
 }
 private bool IsGetEnumerator(MethodInvocationExpression supposedGetEnumerator)
 {
     if (supposedGetEnumerator.MethodExpression.Method.Name != "GetEnumerator")
     {
         return false;
     }
     if (supposedGetEnumerator.MethodExpression.Target == null)
     {
         return false;
     }
     this.foreachCollection = supposedGetEnumerator.MethodExpression.Target;
     return true;
 }
 private bool IsEnumeratorDispose(MethodInvocationExpression methodInvocationExpression)
 {
     if (methodInvocationExpression == null)
     {
         return false;
     }
     if (methodInvocationExpression.MethodExpression.Method.Name == "Dispose")
     {
         return true;
     }
     return false;
 }
 public override void VisitMethodInvocationExpression(MethodInvocationExpression node)
 {
     if (!foundWhile && (IsGetCurrent(node) || IsMoveNextCall(node)))
     {
         ClearState();
     }
     else
     {
         if (IsGetCurrent(node))
         {
             foreachVariableType = node.ExpressionType;
         }
     }
 }
		public override void VisitMethodInvocationExpression(MethodInvocationExpression node)
		{
			bool isExtentionMethod = false;

			if (node.MethodExpression.CodeNodeType == CodeNodeType.MethodReferenceExpression)
			{
				MethodReferenceExpression methodReference = node.MethodExpression;

				MethodReference method = methodReference.Method;

				if (method != null)
				{
					// performance : must be static and do not use method.Resolve that resolves the whole graph.
					if (!method.HasThis && methodReference.MethodDefinition != null)
					{
						isExtentionMethod = methodReference.MethodDefinition.IsExtensionMethod;
					}
				}
			}

			if (isExtentionMethod)
			{
				// TODO: This shouldn't happen but fact is it happens. Seems like some other issue that needs fixing.
				if (node.Arguments.Count > 0)
				{
					ProcessExtensionMethod(node.MethodExpression.Method);
					WriteMethodTarget(node.Arguments[0]);
				}
			}
			else
			{
				if (node.MethodExpression.Target != null)
				{
					WriteMethodTarget(node.MethodExpression.Target);
				}

				if (!node.MethodExpression.Method.HasThis)
				{
					if (node.MethodExpression.MethodDefinition != null && !node.MethodExpression.MethodDefinition.IsExtensionMethod || node.MethodExpression.MethodDefinition == null)
					{
						WriteReferenceAndNamespaceIfInCollision(node.MethodExpression.Method.DeclaringType);
						WriteToken(".");
					}
				}
			}

			WriteMethodReference(node.MethodExpression);
			//VisitMethodReferenceExpression(node.MethodExpression);

			bool indexProp = false;

			WriteToken(indexProp ? IndexLeftBracket : "(");
			if (node.MethodExpression is MethodReferenceExpression)
			{
				EnterMethodInvocation(node.MethodExpression.Method);
				if (!isExtentionMethod)
				{
					VisitMethodParameters(node.Arguments);
				}
				else
				{
					VisitExtensionMethodParameters(node.Arguments);
				}
				LeaveMethodInvocation();
			}
			else
			{
				VisitMethodParameters(node.Arguments);
			}
			WriteToken(indexProp ? IndexRightBracket : ")");
		}
		protected virtual void WriteBaseConstructorInvokation(MethodInvocationExpression baseConstructorInvokation)
		{
		}
		public override void VisitMethodInvocationExpression(MethodInvocationExpression node)
		{
			base.VisitMethodInvocationExpression(node);

			CastMethodArguments(node.MethodExpression.Method, node.Arguments);
		}
 public override ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
 {
     if (node.MethodExpression.Target is VariableReferenceExpression)
     {
         if ((node.MethodExpression.Target as VariableReferenceExpression).Variable == enumerator)
         {
             if (node.MethodExpression.Method.Name == "get_Current")
             {
                 return new VariableReferenceExpression(foreachVariable, null);
             }
         }
     }
     return base.VisitMethodInvocationExpression(node);
 }
        public void VisitMethodInvocationExpression(MethodInvocationExpression node)
        {
            if (node.VirtualCall)
            {
                //Targets of virtual method calls should not be changed
                MethodReferenceExpression method = node.MethodExpression;

                if (!method.Target.HasType)
                {
                    /// The target expression has no type.
                    /// This will result in bad navigation when clicking in the produced method call.
                    return;
                }

                if (method.Target.ExpressionType.FullName == method.Method.DeclaringType.FullName)
                {
                    return;
                }
                MethodReference overridingMethod = method.Method;
                TypeDefinition targetType = method.Target.ExpressionType.Resolve();
                if (targetType == null)
                {
                    // Generics
                    return;
                }
                List<TypeDefinition> inheritanceChain = GetInheritanceChain(targetType, method.Method.DeclaringType.FullName);

                foreach (TypeDefinition type in inheritanceChain)
                {
                    MethodDefinition overrider = type.Methods.FirstOrDefault(x => x.Name == method.Method.Name && x.HasSameSignatureWith(method.Method));
                    if (overrider != null)
                    {
                        overridingMethod = overrider;
                    }
                }

                node.MethodExpression = new MethodReferenceExpression(node.MethodExpression.Target, overridingMethod, node.MethodExpression.MappedInstructions);

                return;
            }

            MethodReferenceExpression methodReferenceExpression = node.MethodExpression;
            if (methodReferenceExpression == null)
            {
                return;
            }

            if (methodReferenceExpression.Target is ThisReferenceExpression)
            {
                TypeDefinition decompiledMethodDeclaringType = baseCodeTransformer.Method.DeclaringType.Resolve();
                if (decompiledMethodDeclaringType != null &&
                    decompiledMethodDeclaringType != methodReferenceExpression.Method.DeclaringType.Resolve())
                {
                    TypeReference baseType = baseCodeTransformer.Method.DeclaringType.BaseType;

                    // does not have a base class.
                    if (baseType == null || baseType.FullName == typeof(System.Object).FullName)
                    {
                        return;
                    }

                    methodReferenceExpression.Target = new BaseReferenceExpression(methodReferenceExpression.Method.DeclaringType,
                        (methodReferenceExpression.Target as ThisReferenceExpression).MappedInstructions);
                }
            }
        }
            public override void VisitMethodInvocationExpression(MethodInvocationExpression node)
            {
                if (node.MethodExpression.Target is VariableReferenceExpression)
                {
                    if ((node.MethodExpression.Target as VariableReferenceExpression).Variable == enumerator)
                    {
                        if (node.MethodExpression.Method.Name != "get_Current")
                        {
                            IsEnumeratorUsed = true;
                        }
                    }
                }

                base.VisitMethodInvocationExpression(node);
            }
		private void WriteSplitPropertySetter(PropertyDefinition property)
		{
			WriteKeyword(KeyWordWriter.Set);
			WriteBeginBlock();
			WriteLine();
			Indent();
			MethodReferenceExpression jdSetterReference = new MethodReferenceExpression(null, property.SetMethod, null);
			MethodInvocationExpression jdMethodInvocation = new MethodInvocationExpression(jdSetterReference, null);
			jdMethodInvocation.Arguments = CopyMethodParametersAsArguments(property.SetMethod);
			ExpressionStatement toWrite = new ExpressionStatement(jdMethodInvocation);
			Write(toWrite);
			WriteLine();
			Outdent();
			WriteEndBlock("Set");
		}