Invoke a Codefix from an IWizard RRS feed

  • Question

  • In Visual Studio 2013 there is a command for implementing an interface called Edit.ImplementInterfaceStubImplicitly.

    In Visual studio 2015 Update 2 the Edit.ImplementInterfaceStubImplicitly command is gone.

    The function Implement Interface is still there, I guess implemented as a Codefix.

    Is there a way to invoke the Implement Interface Codefix from an OleMenuCommand or IWizard?

                IVsTextManager textManager = (IVsTextManager)VSObjects.GlobalProvider.GetService(typeof(SVsTextManager));
                foreach (CodeElement element in ProjectItem.FileCodeModel.CodeElements)
                    if (element.Kind == vsCMElement.vsCMElementNamespace)
                        foreach (CodeElement type in ((CodeNamespace)element).Members)
                            CodeClass codeClass = type as CodeClass;
                            if (codeClass != null &&
                                string classDeclaration = GetClassDeclarationLine(codeClass);
                                List<int> columnNumbers = GetInterfacesStartColumns(classDeclaration, 4);
                                TextPoint textPoint = codeClass.GetStartPoint(vsCMPart.vsCMPartHeader);
                                IVsTextBuffer buffer = null;
                                IVsTextView view;
                                textManager.GetActiveView(1, buffer, out view);
                                foreach (int column in columnNumbers)
                                    view.SetCaretPos(textPoint.Line - 1, column);
                                    VSObjects.DTE.ExecuteCommand("Edit.ImplementInterfaceStubsImplicitly", "");
                                return true;

    This is my code that worked in Visual Studio 2013 that called the Edit.ImplementInterfaceStubImplicitly command. I need to replace this with some code that calls the new implementation of the Implement Interface function in Visual Studio 2015. 

    I can't find any documentation on how to invoke a Codefix from code.

    /Christer Eriksson

    Wednesday, May 11, 2016 7:39 AM

All replies

  • Hi Christer Eriksson,

    >>"In Visual studio 2015 Update 2 the Edit.ImplementInterfaceStubImplicitly command is gone."

    It seems that ImplementInterfaceStubImplicitly is not open for plug-in developers.

    >>"I can't find any documentation on how to invoke a Codefix from code."

    Codefix is not a command.  It is based on code analyzer. If you want to work with CodeFix, you need to  use CodeFIxProvider class.

    CodeFIxProvider is used to fix the code when the diagnostic has been made. GetFixesAsync get the list of fixes and then we can develop a method to fix those changes accordingly. For more information, link below is for your reference.

    Best Regards,
    Li Wang

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Sunday, May 15, 2016 9:52 AM
  • Hi Li!

    Thanks for the answer.

    I guess the only option is to write your own implementation for implementing an interface because I can no longer use the code Visual Studio uses from my extension.


    Thursday, June 16, 2016 10:54 AM