Ejemplo n.º 1
0
        protected override void OnExecute(Microsoft.VisualStudio.Shell.OleMenuCommand command)
        {
            int        curLineIndex, curColumnIndex;
            VSTextView textView = new VSTextView(VSTextView.ActiveTextView);

            if (textView == null)
            {
                MessageBox.Show("textView is null");
                return;
            }

            textView.GetCursorPositon(out curLineIndex, out curColumnIndex);

            //帮助:http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/c62a70eb-d84c-4410-890d-b41a86b2b55f/
            ILangService langService;

            LangService_GetInstance(out langService);
            if (langService == null)
            {
                MessageBox.Show("langService is null");
                return;
            }

            IDECompilerHost compilerHost = new IDECompilerHost();

            IProject prj;
            Project  currentPro = VSDocument.ActiveDocument.ProjectItem.ContainingProject;

            LangService_GetDteProject(langService, currentPro, out prj);
            if (prj == null)
            {
                MessageBox.Show("prj is null");
                return;
            }

            FileName   fileName = new Microsoft.RestrictedUsage.CSharp.Core.FileName(VSDocument.ActiveDocument.FullName);
            CSRPOSDATA data     = new CSRPOSDATA()
            {
                LineIndex = curLineIndex, ColumnIndex = curColumnIndex
            };
            CSharpMember m = Utilities.GetMemberAtLocation(compilerHost, prj, fileName.Value, data);

            if (m != null && m.ReturnType != null)
            {
                string returnName = m.ReturnType.GetFormattedName(InteropTypeFormatFlags.TypeFormatFlags_BestNameGUI);

                returnName = FilterReturnName(returnName);
                if (string.IsNullOrEmpty(returnName))
                {
                    return;
                }

                int insertCol = GetInsertPosition(textView, curLineIndex, curColumnIndex);
                textView.InsertText(returnName + " v =", curLineIndex, insertCol);
                textView.SelectText(curLineIndex, insertCol + returnName.Length + 1, curLineIndex, insertCol + returnName.Length + 2);
            }
        }
Ejemplo n.º 2
0
        protected override void OnExecute(Microsoft.VisualStudio.Shell.OleMenuCommand command)
        {
            int curLineIndex, curColumnIndex;
            VSTextView textView = new VSTextView(VSTextView.ActiveTextView);
            if (textView == null)
            {
                MessageBox.Show("textView is null");
                return;
            }

            textView.GetCursorPositon(out curLineIndex, out curColumnIndex);

            //帮助:http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/c62a70eb-d84c-4410-890d-b41a86b2b55f/
            ILangService langService;
            LangService_GetInstance(out langService);
            if (langService == null)
            {
                MessageBox.Show("langService is null");
                return;
            }

            IDECompilerHost compilerHost = new IDECompilerHost();

            IProject prj;
            Project currentPro = VSDocument.ActiveDocument.ProjectItem.ContainingProject;
            LangService_GetDteProject(langService, currentPro, out prj);
            if (prj == null)
            {
                MessageBox.Show("prj is null");
                return;
            }

            FileName fileName = new Microsoft.RestrictedUsage.CSharp.Core.FileName(VSDocument.ActiveDocument.FullName);
            CSRPOSDATA data = new CSRPOSDATA() { LineIndex = curLineIndex, ColumnIndex = curColumnIndex };
            CSharpMember m = Utilities.GetMemberAtLocation(compilerHost, prj, fileName.Value, data);

            if (m != null && m.ReturnType != null)
            {

                string returnName = m.ReturnType.GetFormattedName(InteropTypeFormatFlags.TypeFormatFlags_BestNameGUI);

                returnName = FilterReturnName(returnName);
                if (string.IsNullOrEmpty(returnName))
                {
                    return;
                }

                int insertCol = GetInsertPosition(textView, curLineIndex, curColumnIndex);
                textView.InsertText(returnName + " v =", curLineIndex, insertCol);
                textView.SelectText(curLineIndex, insertCol + returnName.Length + 1, curLineIndex, insertCol + returnName.Length + 2);
            }
        }