Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

Invoke a Codefix from an IWizard

$
0
0

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 &&
                            HasInterfacesToImplement(codeClass))
                        {
                            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", "");
                            }

                            ProjectItem.Save(ProjectItem.Name);
                            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


Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>