/// <summary> /// Swap base to this unless local implementation. /// </summary> /// <param name="invocationExpression"> /// The invocation expression. /// </param> public static void SwapBaseToThisUnlessLocalImplementation(IInvocationExpression invocationExpression) { bool isOverride = false; bool isNew = false; IPrimaryExpression invokedExpression = invocationExpression.InvokedExpression; if (invokedExpression != null) { IReferenceExpression referenceExpressionNode = invokedExpression as IReferenceExpression; if (referenceExpressionNode != null) { IReferenceExpression referenceExpression = invokedExpression as IReferenceExpression; if (referenceExpression != null) { ICSharpExpression qualifierExpression = referenceExpression.QualifierExpression; if (qualifierExpression is IBaseExpression) { string methodName = referenceExpressionNode.NameIdentifier.Name; ICSharpTypeDeclaration typeDeclaration = invocationExpression.GetContainingNode <ICSharpTypeDeclaration>(true); if (typeDeclaration != null) { foreach (ICSharpTypeMemberDeclaration memberDeclaration in typeDeclaration.MemberDeclarations) { if (memberDeclaration.DeclaredName == methodName) { IMethodDeclaration methodDeclaration = memberDeclaration as IMethodDeclaration; if (methodDeclaration != null) { isOverride = methodDeclaration.IsOverride; isNew = methodDeclaration.IsNew(); break; } } } if (isOverride || isNew) { return; } using (WriteLockCookie.Create(true)) { // swap the base to this ICSharpExpression expression = CSharpElementFactory.GetInstance(invocationExpression.GetPsiModule()).CreateExpression("this"); referenceExpression.SetQualifierExpression(expression); } } } } } } }