/// <summary>
/// Adds a reference to this container using the selector data structure to identify it.
/// </summary>
/// <param name="selectorData">data describing selected component</param>
/// <returns>Reference in case of a valid reference node has been created. Otherwise null</returns>
public virtual ReferenceNode AddReferenceFromSelectorData(VSCOMPONENTSELECTORDATA selectorData, string wrapperTool = null)
{
//Make sure we can edit the project file
ThreadHelper.ThrowIfNotOnUIThread();
if (!this.ProjectMgr.QueryEditProjectFile(false))
{
throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
}
//Create the reference node
ReferenceNode node = null;
try
{
node = CreateReferenceNode(selectorData, wrapperTool);
}
catch (ArgumentException)
{
// Some selector data was not valid.
}
//Add the reference node to the project if we have a valid reference node
if (node != null)
{
// Does such a reference already exist in the project?
ReferenceNode existingNode;
if (node.IsAlreadyAdded(out existingNode))
{
return(existingNode);
}
// This call will find if the reference is in the project and, in this case
// will not add it again, so the parent node will not be set.
node.AddReference();
if (null == node.Parent)
{
// The reference was not added, so we can not return this item because it
// is not inside the project.
return(null);
}
}
return(node);
}