1
我做這個代碼後:我要訪問選定類或接口當右鍵點擊項目,新項目添加到VS 2010
`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 oCommandBar = (CommandBarPopup)SEPopUps.Controls["Project"];
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);
}
protected void oSubMenuItemHandler_Click(object CommandaBarControl,ref bool handled, ref bool cancelDefault)
{
// I Want to access object of selected class or interface
MessageBox.Show("Test");
}`
我開發添加在反映VS類的所有數據2010. 請我想訪問所選的類或接口來反映所有成員數據。 任何一個可以幫助我
我這樣做代碼:'object [] ps =(object [])_ applicationObject.ActiveSolutionProjec TS; foreach(Project pr in ps) ProjectItems _ProjectItems = pr.ProjectItems; CodeModel hh = _ProjectItems.ContainingProject.CodeModel; CodeElements els = hh.CodeElements; }'我無法訪問項目的類和接口 –
我更新了我的答案和一個工作示例 –
感謝斯蒂芬鮑爾它的工作原理,但我可以訪問類,並得到它的類型來做到這一點:'MethodInfo [] mi = obj.GetType ()。GetMethods();''// obj我從選定的項目得到它 –