/// <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; ICSharpExpression invokedExpression = invocationExpression.InvokedExpression; if (invokedExpression != null) { IReferenceExpressionNode referenceExpressionNode = invokedExpression as IReferenceExpressionNode; 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.GetContainingElement <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); } } } } } } }
/// <summary> /// Swap to built in type alias. /// </summary> /// <param name="node"> /// The node to process. /// </param> public static void SwapToBuiltInTypeAlias(ITreeNode node) { for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { ITypeArgumentListNode typeArgumentListNode = currentNode as ITypeArgumentListNode; if (typeArgumentListNode != null) { SwapGenericDeclarationToBuiltInType(typeArgumentListNode); } else { IMethodDeclarationNode methodDeclarationNode = currentNode as IMethodDeclarationNode; if (methodDeclarationNode != null) { SwapReturnTypeToBuiltInType(methodDeclarationNode); } else { IVariableDeclarationNode variableDeclaration = currentNode as IVariableDeclarationNode; if (variableDeclaration != null) { SwapVariableDeclarationToBuiltInType(variableDeclaration); } else { IObjectCreationExpressionNode creationExpressionNode = currentNode as IObjectCreationExpressionNode; if (creationExpressionNode != null) { SwapObjectCreationToBuiltInType(creationExpressionNode); } else { IArrayCreationExpressionNode arrayCreationNode = currentNode as IArrayCreationExpressionNode; if (arrayCreationNode != null) { SwapArrayCreationToBuiltInType(arrayCreationNode); } else { IReferenceExpressionNode referenceExpressionNode = currentNode as IReferenceExpressionNode; if (referenceExpressionNode != null) { SwapReferenceExpressionToBuiltInType(referenceExpressionNode); } } } } } } if (currentNode != null && currentNode.FirstChild != null) { SwapToBuiltInTypeAlias(currentNode.FirstChild); } } }