简体   繁体   English

ProjectItemsEvents.ItemAdded:如何发现项目类型?

[英]ProjectItemsEvents.ItemAdded: how can I discover the item type?

I'm beginning to develop a VSPackage and would like to know when a new reference is added to a project but subscribing the ItemAdded of ProjectItemsEvents gives me a ProjectItem object and I don't know how to check if it is a reference. 我开始开发VSPackage,想知道何时将新引用添加到项目中,但是订阅ProjectItemsEvents的ItemAdded可以给我一个ProjectItem对象,而且我不知道如何检查它是否为引用。 Can somebody help me to solve that problem? 有人可以帮我解决这个问题吗? Thanks in advance. 提前致谢。

Fortunately I found that the class VSLangProj.ReferencesEvents fire the ReferenceAdded event I need. 幸运的是,我发现类VSLangProj.ReferencesEvents触发了我需要的ReferenceAdded事件。 So, I've done: 因此,我已经完成:

private static ReferencesEvents _refEvents;
private static Events2 _dteEvents;
public void SubscribeEvents()
{
 EnvDTE.DTE dte = (EnvDTE.DTE)ServiceProvider.GetService(typeof(EnvDTE.DTE));
 _dteEvents = dte.Events as Events2;
 _refEvents = (ReferencesEvents)_dteEvents.GetObject("CSharpReferencesEvents");
 _refEvents.ReferenceAdded += new _dispReferencesEvents_ReferenceAddedEventHandler(ReferenceAdded);
}

private void ReferenceAdded(Reference pReference)
{
  // do some stuff.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM