-3

これは私のコードです:

    public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance = (AddIn)addInInst;
            if (connectMode == ext_ConnectMode.ext_cm_UISetup)
            {
                object[] contextGUIDS = new object[] { };
                Commands2 commands = (Commands2)_applicationObject.Commands;

                CommandBar SECommandBar = ((CommandBars)_applicationObject.CommandBars)["Context Menus"];
                CommandBarPopup SEPopUps = (CommandBarPopup)SECommandBar.Controls["Project and Solution Context Menus"];
                CommandBarPopup ooCommandBar = (CommandBarPopup)SEPopUps.Controls["Project"];
                CommandBarPopup oCommandBar = (CommandBarPopup)SEPopUps.Controls["Item"];



                CommandBarControl oControl = (CommandBarControl)
                  oCommandBar.Controls.Add(MsoControlType.msoControlButton,
                  System.Reflection.Missing.Value,
                  System.Reflection.Missing.Value, 1, true);
                // Set the caption of the menuitem
                oControl.Caption = "Create Documentation";

                oSubMenuItemHandler = _applicationObject.Events.get_CommandBarEvents(oControl) as CommandBarEventsClass;
                oSubMenuItemHandler.Click += new _dispCommandBarControlEvents_ClickEventHandler(oSubMenuItemHandler_Click);


            }
        }

 public void oSubMenuItemHandler_Click(object CommandaBarControl, ref bool handled, ref bool cancelDefault)
        {
SelectedItems doc = _applicationObject.SelectedItems;
// i want to get type of selected Class
}

こんなことできるかな。選択したクラスのタイプにアクセスしてリフレクションを作成し、すべてのメソッドと属性を取得するのに役立つ

4

2 に答える 2

0

これを行うには、.cs ファイルをプログラムでコンパイルする必要がありますが、これは簡単な作業ではありません。

それに関するまともなmsdn記事があります:「C#コンパイラを使用してコードをプログラムでコンパイルする方法」

コンパイルしたら、リフレクションを使用して、生成されたアセンブリから型を取得できます: "Assembly.GetTypes Method"

于 2013-08-21T09:56:38.270 に答える