public static bool IsTypeOfExpression(this MethodInvocationExpression self, out TypeReference typeReference) { typeReference = null; MethodReferenceExpression method_ref = self.MethodExpression; if (method_ref == null) { return(false); } var method = method_ref.Method; if ((method.CallingConvention == Mono.Cecil.MethodCallingConvention.StdCall) || (method.DeclaringType.FullName != "System.Type") || (method.Name != "GetTypeFromHandle")) { return(false); } if (self.Arguments.Count != 1) { return(false); } MemberHandleExpression memberHandle = self.Arguments[0] as MemberHandleExpression; if (memberHandle == null) { return(false); } typeReference = memberHandle.MemberReference as TypeReference; return(typeReference != null); }
public override ICodeNode VisitPropertyReferenceExpression(PropertyReferenceExpression node) { MethodReferenceExpression methodRefExpression = node.MethodExpression; if (methodRefExpression.Target != null) { if (methodRefExpression.Target.CodeNodeType == CodeNodeType.VariableReferenceExpression && asyncData.AwaiterVariables.Contains((methodRefExpression.Target as VariableReferenceExpression).Variable)) { VariableReference awaiterVariable = (methodRefExpression.Target as VariableReferenceExpression).Variable; if (currentAwaiterVariable == awaiterVariable) { if (methodRefExpression.Method.Name == "get_IsCompleted") { if (matcherState == MatcherState.FindIsCompletedInvoke) { matcherState = MatcherState.FindInitObj | MatcherState.FindGetResultInvoke; return(null); } } } matcherState = MatcherState.Stopped; return(node); } } return(base.VisitPropertyReferenceExpression(node)); }
private void ProcessStringMethod(MethodInvocationExpression node, MethodReferenceExpression methodRef) { MethodReference method = methodRef.Method; if (method.Parameters.Count != 1 || !IsSystemString(method.Parameters[0].ParameterType)) { UnsupportedExpression(methodRef); } switch (method.Name) { case "Contains": PushComparison(methodRef.Target, node.Arguments[0], ComparisonOperator.Contains); break; case "StartsWith": PushComparison(methodRef.Target, node.Arguments[0], ComparisonOperator.StartsWith); break; case "EndsWith": PushComparison(methodRef.Target, node.Arguments[0], ComparisonOperator.EndsWith); break; case "Equals": PushComparison(methodRef.Target, node.Arguments[0], ComparisonOperator.ValueEquality); break; default: UnsupportedExpression(methodRef); break; } }
public override void Visit(MethodInvocationExpression node) { MethodReferenceExpression methodRef = node.Target as MethodReferenceExpression; if (null == methodRef) { UnsupportedExpression(node); } MethodReference method = methodRef.Method; if (IsOperator(method)) { ProcessOperatorMethodInvocation(node, method); return; } if (IsSystemString(method.DeclaringType)) { ProcessStringMethod(node, methodRef); return; } ProcessRegularMethodInvocation(node, methodRef); }
public override void VisitMethodReferenceExpression(MethodReferenceExpression node) { this.states.Push(0); this.VisitMethodReferenceExpression(node); dummyVar0 = this.states.Pop(); return; }
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 ExplicitCastExpression((Expression)codeTransformer.Visit(node.Arguments[0]), node.ExpressionType, node.InvocationInstructions)); } if (method.Name == "op_Implicit") { return(new ImplicitCastExpression((Expression)codeTransformer.Visit(node.Arguments[0]), node.ExpressionType, node.InvocationInstructions)); } 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); }
private static MethodDefinition LoadExternalMethodDefinition(MethodReferenceExpression methodRef) { MethodReference method = methodRef.Method; AssemblyDefinition assemblyDef = new AssemblyResolver(_assemblyCachingStrategy).ForTypeReference(method.DeclaringType); TypeDefinition type = assemblyDef.MainModule.GetType(method.DeclaringType.FullName); return(GetMethod(type, method)); }
public override void VisitMethodReferenceExpression(MethodReferenceExpression node) { if (state == SearchState.Propagation) { canBePropagated = false; return; } base.VisitMethodReferenceExpression(node); }
private Expression GetTypeHandleExpression(TypeReference typeReference, IEnumerable <Instruction> instructions) { TypeOfExpression typeOfExpression = new TypeOfExpression(typeReference, null); MethodReference getHandleReference = GetHandlePropertyGetterReference(typeof(Type), "get_TypeHandle"); MethodReferenceExpression getHandleReferenceExpression = new MethodReferenceExpression(typeOfExpression, getHandleReference, null); MethodInvocationExpression methodInvoke = new MethodInvocationExpression(getHandleReferenceExpression, instructions); return(new PropertyReferenceExpression(methodInvoke, null)); }
public override void VisitMethodReferenceExpression(MethodReferenceExpression node) { if (this.state == ExpressionPropagationStep.ExpressionTreeVisitor.SearchState.Propagation) { this.canBePropagated = false; return; } this.VisitMethodReferenceExpression(node); return; }
/// <summary> /// Replaces this pointer if there is one in the inlined method. /// </summary> /// <param name="node"> /// A <see cref="MethodReferenceExpression"/> /// </param> /// <returns> /// A <see cref="ICodeNode"/> /// </returns> public override ICodeNode VisitMethodReferenceExpression(MethodReferenceExpression node) { if (thisSubstitution != null && node.Target == null && node.Method.DeclaringType == source.Method.DeclaringType) { node.Target = thisSubstitution; } return(base.VisitMethodReferenceExpression(node)); }
private static bool IsActivateInvocation(MethodInvocationExpression invocation) { MethodReferenceExpression methodRef = invocation.Target as MethodReferenceExpression; if (null == methodRef) { return(false); } return(IsActivateMethod(methodRef.Method)); }
/// <summary> /// This handles the case MethodInvocationExpr(...). /// If the MethodInvocationExpr is appropriate for inlining then we inline it or if it is not appropriate /// we check if there is in the arguments something to be inlined. /// For example: /// <code> MethodInv1(somearg1, Inlinee(...), someargs...) </code> /// In that case we make the substitution: /// <code> /// sometype somevar = Inlinee(...);//here we inline the actual code of the method /// MethodInv1(somearg1, somevar, someargs...) /// </code> /// </summary> /// <param name="node"> /// A <see cref="MethodInvocationExpression"/> /// </param> /// <returns> /// A <see cref="ICodeNode"/> /// </returns> public override ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node) { MethodReferenceExpression methodRef = (MethodReferenceExpression)node.Method; if (IsInlineable(methodRef.Method)) { currentSideEffect.mInvokeNode = node; VariableReferenceExpression varRefExp = null; //Mono.Cecil 0.9.3 migration: if (methodRef.Method.ReturnType.ReturnType.FullName != "System.Void") { //Mono.Cecil 0.9.3 migration: currentSideEffect.mInvokeNodeVar = RegisterVariable(methodRef.Method.ReturnType.ReturnType, source.Method); if (methodRef.Method.ReturnType.FullName != "System.Void") { currentSideEffect.mInvokeNodeVar = RegisterVariable(methodRef.Method.ReturnType, source.Method); varRefExp = new VariableReferenceExpression(currentSideEffect.mInvokeNodeVar); } sideEffects.Add(currentSideEffect); currentSideEffect = new SideEffectInfo(); return(varRefExp); } // else if (HasSideEffects(methodRef.Method)) { // currentSideEffect.SideEffectsInNode.Add(node); // VariableDefinition @var = RegisterVariable(methodRef.Method.ReturnType.ReturnType, source.Method); // currentSideEffect.SideEffectsInNodeVar.Add(@var); // return new VariableReferenceExpression(@var); // // } //node.Method = (Expression) Visit(node.Method); var argExpand = new CodeNodeCollection <Expression>(); for (int i = 0; i < node.Arguments.Count; i++) { ICodeNode currentArgument = (ICodeNode)Visit(node.Arguments[i]); var argAsCollection = currentArgument as CodeNodeCollection <Expression>; if (argAsCollection != null) { for (int j = 0; j < argAsCollection.Count - 1; j++) { argExpand.Add(argAsCollection[j]); } node.Arguments[i] = argAsCollection[argAsCollection.Count - 1]; } } if (argExpand.Count > 0) { argExpand.Add(node); return(argExpand); } else { return(node); } }
private static MethodDefinition MethodDefinitionFor(MethodInvocationExpression invocation) { MethodReferenceExpression methodRef = invocation.Target as MethodReferenceExpression; if (null == methodRef) { return(null); } return(GetMethodDefinition(methodRef)); }
bool IsCallOnEnumerator(MethodReferenceExpression method_reference_expression, string method_name) { if (method_reference_expression.Method.Name != method_name) { return(false); } if (!IsEnumerator(method_reference_expression.Target)) { return(false); } return(true); }
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); }
/// <summary> /// Creates a delegate constructr /// </summary> /// <param name="delegateType"> /// The delegate type /// </param> /// <param name="method"> /// The listener method /// </param> /// <returns> /// A <see cref="DelegateCreateExpression"/> representing the /// delegate creation. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="delegateType"/> or <paramref name="method"/> /// is a null reference (Nothing in Visual Basic) /// </exception> public static DelegateCreateExpression Delegate( Type delegateType, MethodReferenceExpression method) { if (delegateType == null) { throw new ArgumentNullException("delegateType"); } if (method == null) { throw new ArgumentNullException("method"); } return(new DelegateCreateExpression(new TypeTypeDeclaration(delegateType), method)); }
public override void VisitMethodReferenceExpression(MethodReferenceExpression node) { if (node.Target != null) { Visit(node.Target); WriteToken("."); } if (!node.Method.HasThis) { WriteReference(node.Method.DeclaringType); WriteToken("."); } Write(node.Method.Name); }
public override ICodeNode VisitMethodReferenceExpression(MethodReferenceExpression node) { V_0 = node.get_Method().Resolve(); V_1 = this.context.get_TypeContext().get_CurrentType(); if (V_0 == null || (object)V_0.get_DeclaringType() != (object)V_1 && !V_0.get_DeclaringType().IsNestedIn(V_1)) { return(this.VisitMethodReferenceExpression(node)); } if (V_0.get_IsGetter() || V_0.get_IsSetter() || !V_0.IsCompilerGenerated(true) && !this.CheckTypeForCompilerGeneratedAttribute(V_0.get_DeclaringType())) { return(this.VisitMethodReferenceExpression(node)); } V_2 = null; if (V_0.get_Body() != null) { V_5 = this.CreateDecompilationContext(V_0); V_2 = V_0.get_Body().DecompileLambda(this.context.get_Language(), V_5); if (V_2.get_Statements().get_Count() == 1 && V_2.get_Statements().get_Item(0).get_CodeNodeType() == 5 && (V_2.get_Statements().get_Item(0) as ExpressionStatement).get_Expression().get_CodeNodeType() == 57) { V_6 = (V_2.get_Statements().get_Item(0) as ExpressionStatement).get_Expression() as ReturnExpression; V_7 = new ShortFormReturnExpression(V_6.get_Value(), V_6.get_MappedInstructions()); V_2 = new BlockStatement(); V_2.get_Statements().Add(new ExpressionStatement(V_7)); } this.context.get_MethodContext().get_VariableDefinitionToNameMap().AddRange <VariableDefinition, string>(V_5.get_MethodContext().get_VariableDefinitionToNameMap()); this.context.get_MethodContext().get_VariableNamesCollection().UnionWith(V_5.get_MethodContext().get_VariableNamesCollection()); this.context.get_MethodContext().AddInnerMethodParametersToContext(V_5.get_MethodContext()); this.context.get_MethodContext().get_GotoStatements().AddRange(V_5.get_MethodContext().get_GotoStatements()); this.context.get_MethodContext().get_GotoLabels().AddRange <string, Statement>(V_5.get_MethodContext().get_GotoLabels()); } V_3 = new ExpressionCollection(); V_4 = LambdaExpressionsHelper.HasAnonymousParameter(V_0.get_Parameters()); V_8 = V_0.get_Parameters().GetEnumerator(); try { while (V_8.MoveNext()) { V_9 = V_8.get_Current(); V_3.Add(new LambdaParameterExpression(V_9, !V_4, null)); } } finally { V_8.Dispose(); } return(new LambdaExpression(V_3, V_2, V_0.IsAsync(), V_0.IsFunction(), node.get_Method().get_Parameters(), false, node.get_MappedInstructions())); }
public override ICodeNode VisitMethodReferenceExpression(MethodReferenceExpression node) { ICodeNode result = base.VisitMethodReferenceExpression(node); int value; if (expressionNumbers.TryGetValue(node, out value)) { // } else { expressionNumbers.Add(node, expressionCnt++); } return(result); }
public override ICodeNode VisitMethodReferenceExpression(MethodReferenceExpression node) { MethodDefinition methodDefinition = node.Method.Resolve(); TypeDefinition currentType = context.TypeContext.CurrentType; if (methodDefinition == null || methodDefinition.DeclaringType != currentType && !methodDefinition.DeclaringType.IsNestedIn(currentType)) { return(base.VisitMethodReferenceExpression(node)); } if ((!methodDefinition.IsGetter) && (!methodDefinition.IsSetter) && (methodDefinition.IsCompilerGenerated() || CheckTypeForCompilerGeneratedAttribute(methodDefinition.DeclaringType))) { BlockStatement statement = null; if (methodDefinition.Body != null) { DecompilationContext innerContext = CreateDecompilationContext(methodDefinition); statement = methodDefinition.Body.DecompileLambda(Language, innerContext); if ((statement.Statements.Count == 1) && (statement.Statements[0].CodeNodeType == CodeNodeType.ExpressionStatement) && ((statement.Statements[0] as ExpressionStatement).Expression.CodeNodeType == CodeNodeType.ReturnExpression)) { ReturnExpression returnExpression = (statement.Statements[0] as ExpressionStatement).Expression as ReturnExpression; ShortFormReturnExpression shortFormReturnExpression = new ShortFormReturnExpression(returnExpression.Value, returnExpression.MappedInstructions); statement = new BlockStatement(); statement.Statements.Add(new ExpressionStatement(shortFormReturnExpression)); } this.context.MethodContext.VariableDefinitionToNameMap.AddRange(innerContext.MethodContext.VariableDefinitionToNameMap); this.context.MethodContext.VariableNamesCollection.UnionWith(innerContext.MethodContext.VariableNamesCollection); this.context.MethodContext.AddInnerMethodParametersToContext(innerContext.MethodContext); this.context.MethodContext.GotoStatements.AddRange(innerContext.MethodContext.GotoStatements); this.context.MethodContext.GotoLabels.AddRange(innerContext.MethodContext.GotoLabels); } ExpressionCollection expressionCollection = new ExpressionCollection(); bool hasAnonymousParameter = LambdaExpressionsHelper.HasAnonymousParameter(methodDefinition.Parameters); foreach (ParameterDefinition parameter in methodDefinition.Parameters) { expressionCollection.Add(new LambdaParameterExpression(parameter, !hasAnonymousParameter, null)); } return(new LambdaExpression(expressionCollection, statement, methodDefinition.IsAsync(), methodDefinition.IsFunction(), node.Method.Parameters, false, node.MappedInstructions)); } return(base.VisitMethodReferenceExpression(node)); }
bool IsBooleanExpression(Expression expression) { switch (expression.CodeElementType) { case CodeElementType.BinaryExpression: return(IsComparisonOperator(((BinaryExpression)expression).Operator)); case CodeElementType.MethodInvocationExpression: MethodReferenceExpression mre = ((MethodInvocationExpression)expression).Target as MethodReferenceExpression; if (null != mre) { return(mre.Method.ReturnType == _SystemBoolean); } break; } return(false); }
private Expression GetFieldHandleExpression(FieldReference fieldReference, IEnumerable <Instruction> instructions) { TypeDefinition corlibTypeTypeDefinition = GetSystemTypeTypeDefinition(); MethodReference getFieldReference = GetSystemTypeMethodReference(corlibTypeTypeDefinition, "GetField", new string[] { "System.String" }); TypeOfExpression typeOfExpression = new TypeOfExpression(fieldReference.DeclaringType, null); MethodReferenceExpression getFieldMethodReferenceExpression = new MethodReferenceExpression(typeOfExpression, getFieldReference, null); MethodInvocationExpression getFieldInfoInvocation = new MethodInvocationExpression(getFieldMethodReferenceExpression, null); getFieldInfoInvocation.Arguments.Add(new LiteralExpression(fieldReference.Name, this.typeSystem, null)); MethodReference getFieldHandleReference = GetHandlePropertyGetterReference(typeof(System.Reflection.FieldInfo), "get_FieldHandle"); MethodInvocationExpression getFieldHandleInvoke = new MethodInvocationExpression(new MethodReferenceExpression(getFieldInfoInvocation, getFieldHandleReference, null), instructions); return(new PropertyReferenceExpression(getFieldHandleInvoke, null)); }
public override ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node) { MethodReferenceExpression methodRefExpression = node.MethodExpression; if (methodRefExpression.Target != null) { if (methodRefExpression.Target.CodeNodeType == CodeNodeType.VariableReferenceExpression && asyncData.AwaiterVariables.Contains((methodRefExpression.Target as VariableReferenceExpression).Variable)) { VariableReference awaiterVariable = (methodRefExpression.Target as VariableReferenceExpression).Variable; if (currentAwaiterVariable == awaiterVariable) { if (methodRefExpression.Method.Name == "get_IsCompleted") { if (matcherState == MatcherState.FindIsCompletedInvoke) { matcherState = MatcherState.FindInitObj | MatcherState.FindGetResultInvoke; return(null); } } else if (methodRefExpression.Method.Name == "GetResult") { if ((matcherState & MatcherState.FindGetResultInvoke) == MatcherState.FindGetResultInvoke) { matcherState ^= MatcherState.FindGetResultInvoke; return(new AwaitExpression((Expression)Visit(awaitedExpression), methodRefExpression.Method.ReturnType, node.UnderlyingSameMethodInstructions)); } } } matcherState = MatcherState.Stopped; return(node); } else if (methodRefExpression.Target.CodeNodeType == CodeNodeType.FieldReferenceExpression && (methodRefExpression.Target as FieldReferenceExpression).Field.Resolve() == builderField) { if (methodRefExpression.Method.Name == "SetResult") { Expression returnValue = node.Arguments.Count > 0 ? node.Arguments[0] : null; return(new ReturnExpression(returnValue, methodRefExpression.UnderlyingSameMethodInstructions)); } } } return(base.VisitMethodInvocationExpression(node)); }
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); }
private MethodReferenceExpression GetDisposeMethodReference(Statement stmt) { ExpressionStatement expressionStatement = (ExpressionStatement)stmt; if (!(expressionStatement.Expression is MethodInvocationExpression)) { return(null); } MethodInvocationExpression methodInvocation = (MethodInvocationExpression)expressionStatement.Expression; if (methodInvocation.Arguments.Count != 0) { return(null); } if (!(methodInvocation.MethodExpression is MethodReferenceExpression)) { return(null); } MethodReferenceExpression methodReference = methodInvocation.MethodExpression; TypeReference declaringType = methodInvocation.MethodExpression.Method.DeclaringType; if (declaringType == null) { return(null); } TypeDefinition iDisposable = Utilities.GetCorlibTypeReference(typeof(System.IDisposable), declaringType.Module).Resolve(); if (iDisposable == null) { return(null); } if (methodReference.Method.IsImplementationOf(iDisposable)) { return(methodReference); } return(null); }
private void IntroduceLocalAllArguments_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea) { // Are we on a MethodReferenceExpression? LanguageElement element = CodeRush.Source.Active; MethodReferenceExpression MRE = element as MethodReferenceExpression; if (MRE == null) { return; } // Does Method have arguments? LanguageElement parent = MRE.Parent; ExpressionCollection arguments = getArguments(parent); if (arguments == null) { return; } ea.Available = true; }
// public override void VisitBreakStatement (BreakStatement node) // { // // } // // public override void VisitContinueStatement (ContinueStatement node) // { // } // // public override void VisitForStatement (ForStatement node) // { // Visit (node.Initializer); // Visit (node.Condition); // Visit (node.Increment); // Visit (node.Body); // } // // public override void VisitForEachStatement (ForEachStatement node) // { // Visit (node.Variable); // Visit (node.Expression); // Visit (node.Body); // } // // public override void VisitConditionCase (ConditionCase node) // { // Visit (node.Condition); // } // // public override void VisitDefaultCase (DefaultCase node) // { // } // // public override void VisitSwitchStatement (SwitchStatement node) // { // Visit (node.Expression); // Visit (node.Cases); // } // // public override void VisitCatchClause (CatchClause node) // { // Visit (node.Body); // Visit (node.Variable); // } // // public override void VisitTryStatement (TryStatement node) // { // Visit (node.Try); // Visit (node.CatchClauses); // Visit (node.Fault); // Visit (node.Finally); // } // //// public override void VisitBlockExpression (BlockExpression node) //// { //// Visit (node.Expressions); //// } // public override void VisitMethodInvocationExpression(MethodInvocationExpression node) { Visit(node.Method); Visit(node.Arguments); MethodReferenceExpression methRefExp = node.Method as MethodReferenceExpression; if (methRefExp != null) { if (methRefExp.Method.Resolve().IsVirtual) { cil.EmitInstruction(OpCodes.Callvirt, methRefExp.Method); } else { cil.EmitInstruction(OpCodes.Call, methRefExp.Method); } } }
private void IntroduceLocalAllArguments_Execute(Object sender, ApplyContentEventArgs ea) { TextDocument ActiveDoc = CodeRush.Documents.ActiveTextDocument; using (ActiveDoc.NewCompoundAction("Introduce Local (All Arguments)")) { LanguageElement element = CodeRush.Source.Active; MethodReferenceExpression MRE = element as MethodReferenceExpression; LanguageElement parent = MRE.Parent; ExpressionCollection arguments = getArguments(parent); for (int i = 0; i < arguments.Count; i++) { // Select expression CodeRush.Selection.SelectRange(arguments[i].Range); // Invoke refactoring to Introduce Local. ExecuteRefactoring("Introduce Local"); ActiveDoc.SetText(GetSelectionRange(), "Param" + (i + 1)); } } }
public override ICodeNode VisitTryStatement(TryStatement node) { if (node.Finally != null && node.Finally.Body.Statements.Count == 1 && node.Finally.Body.Statements[0].CodeNodeType == CodeNodeType.ExpressionStatement) { ExpressionStatement theExpressionStatement = node.Finally.Body.Statements[0] as ExpressionStatement; if (theExpressionStatement.Expression.CodeNodeType == CodeNodeType.MethodInvocationExpression) { MethodReferenceExpression theMethodReferenceExpression = (theExpressionStatement.Expression as MethodInvocationExpression).MethodExpression; if (theMethodReferenceExpression != null && theMethodReferenceExpression.Method != null && theMethodReferenceExpression.Method.DeclaringType != null) { TypeDefinition theDeclaringTypeDef = theMethodReferenceExpression.Method.DeclaringType.Resolve(); if (theDeclaringTypeDef == yieldDeclaringType) { node.Finally = new FinallyClause(theMethodReferenceExpression.Method.Resolve().Body.Decompile(this.decompilationContext.Language), node.Finally.UnderlyingSameMethodInstructions); } } } } return(base.VisitTryStatement(node)); }
private bool QualifiedWithNamespace(MethodReferenceExpression methodReference) { LanguageElement ClassReference = (LanguageElement)methodReference.Nodes[0]; return (ClassReference.Nodes.Count > 0); }