public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
    {
        EnvDTE.TextSelection ts = DTE.ActiveWindow.Selection as EnvDTE.TextSelection;
        if (ts == null)
        {
            throw new Exception("No Selection");
        }

        EnvDTE.CodeParameter codeParam = ts.ActivePoint.CodeElement[vsCMElement.vsCMElementParameter] as EnvDTE.CodeParameter;
        if (codeParam == null)
        {
            throw new Exception("Not Parameter");
        }

        System.Type tClass     = GetTypeByName(DTE, package, codeParam.Type.AsFullName);
        string      properties = System.Environment.NewLine;

        foreach (var p in tClass.GetProperties())
        {
            properties += codeParam.Name + "." + p.Name + System.Environment.NewLine;
        }

        // Move into the method and dump the properties there
        ts.FindText("{");
        ts.Insert("{" + properties);
    }
Esempio n. 2
0
        private void PerformBugTracker(bool dotNet)
        {
            //! https://blogs.msdn.microsoft.com/vsx/2016/04/21/how-to-add-a-custom-paste-special-command-to-the-vs-editor-menu/

            Application.DoEvents();

            EnvDTE.TextSelection selection = (EnvDTE.TextSelection) this.CommandManager.ApplicationObject.ActiveDocument.Selection;
            string text           = selection.Text;
            string text_trim      = text.Trim();
            bool   is_numeric     = int.TryParse(text_trim, out int n);
            string bug_tracker_id = is_numeric ? text_trim : "00000";

            string        date   = DateTime.Now.ToString("yyyy-MM-dd");
            List <string> result = new List <string>();

            string comment_line = dotNet ?
                                  "/// @date " + date + "  @author " + this.CommandManager.UserName + "  @bugtracker{" + bug_tracker_id + "}" :
                                  "//! @date " + date + "  @author " + this.CommandManager.UserName + "  @bugtracker{" + bug_tracker_id + "}";

            /* TODO $$$ `selection.CurrentColumn` does not give a proper result
             *      try
             *      {
             *              int column = selection.CurrentColumn;
             *              if (column > 0)
             *              {
             *                      string indent_str = "";
             *                      for (int i = 0; i < column; ++i)
             *                              indent_str += " ";
             *                      comment_line = indent_str + comment_line;
             *              }
             *      }
             *      catch {}
             */

            result.Add(comment_line);

            string str = "";

            for (int i = 0; i < result.Count; i++)
            {
                str += result[i] + "\n";
            }

            selection.Insert(str, 2);
            if (!is_numeric)
            {
                selection.FindText("00000");
            }
        }