ISelectionContainer.GetObjects 返回的对象的类型是什么?
我正在为 VS2010 编写一个扩展,我的包实现了 IVsSelectionEvents
来跟踪解决方案资源管理器中的选择:
public int OnSelectionChanged(
IVsHierarchy pHierOld,
uint itemidOld,
IVsMultiItemSelect pMISOld,
ISelectionContainer pSCOld,
IVsHierarchy pHierNew,
uint itemidNew,
IVsMultiItemSelect pMISNew,
ISelectionContainer pSCNew)
{
if (pSCNew != null)
{
uint count;
pSCNew.CountObjects((uint) Constants.GETOBJS_SELECTED, out count);
object[] selectedObjects = new object[count];
pSCNew.GetObjects((uint) Constants.GETOBJS_SELECTED, count, selectedObjects);
// What is the type of this object?
var selectedItem = selectedObjects[0] as ???;
}
return VSConstants.S_OK;
}
GetObjects
填充了一个对象数组,但是我不知道不知道这些对象的实际类型是什么。 GetType
返回System.__ComObject
,这不是很有帮助。我假设这些对象实现了一个已知的接口,但我如何知道是哪一个?这似乎没有在任何地方记录...目前我正在使用 dynamic
来访问对象的属性,但这并不理想,而且无论如何我不知道哪些方法是由这个对象(我只能在“监视”窗口中看到属性)
有谁知道解决方案资源管理器中的项目项实现了哪个接口?
I'm writing an extension for VS2010, and my package implements IVsSelectionEvents
to track the selection in the solution explorer:
public int OnSelectionChanged(
IVsHierarchy pHierOld,
uint itemidOld,
IVsMultiItemSelect pMISOld,
ISelectionContainer pSCOld,
IVsHierarchy pHierNew,
uint itemidNew,
IVsMultiItemSelect pMISNew,
ISelectionContainer pSCNew)
{
if (pSCNew != null)
{
uint count;
pSCNew.CountObjects((uint) Constants.GETOBJS_SELECTED, out count);
object[] selectedObjects = new object[count];
pSCNew.GetObjects((uint) Constants.GETOBJS_SELECTED, count, selectedObjects);
// What is the type of this object?
var selectedItem = selectedObjects[0] as ???;
}
return VSConstants.S_OK;
}
GetObjects
fills an array of objects, but I don't know what is the actual type of these objects. GetType
returns System.__ComObject
, which is not very helpful. I assume these objects implement a known interface, but how do I know which one? This doesn't seem to be documented anywhere... Currently I'm using dynamic
to access the properties of the object, but it's not ideal, and anyway I don't know which methods are exposed by this object (I can only see the properties in the Watch window)
Does anyone know which interface is implemented by project items in the solution explorer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,看起来 GetObjects 返回的项目的类型为
文件属性
。但无论如何,我找到了一种更简单的方法,使用 EnvDTE 代替...... 可以使用以下方法从层次结构和项目 ID 中检索EnvDTE.ProjectItem
对象:OK, so it seems that the items returned by GetObjects are of type
FileProperties
. But anyway, I found a much easier approach, using EnvDTE instead... AnEnvDTE.ProjectItem
object can be retrieved from the hierarchy and item id with this method: