ProjectItem.Collection wrong for folders of SQL Server projects of VSTS for Database Professionals - by Carlos J. Quintero

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


2
0
Sign in
to vote
ID 296758 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 9/5/2007 5:05:00 AM
Access Restriction Public

Description

I am sort of reopening the bug that I reported in http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=295434 because it was closed without acknowledging the bug and providing a f¡x. The problem has nothing to do with scenarios or what to accomplish with DTE. It is just that the current implementation of the automation model VS 2005 and VS 2008 Beta2 has a bug. I will try to explain it much better and even provide where the code of MS is wrong:

- An EnvDTE.ProjectItem of a project can be a folder or a file.
- A folder contains folders or files
- A file can contain dependant files (such as .designer.cs or .resx) 
- For that purpose, the EnvDTE.ProjectItem class of the automation model provides two properties:

1) ProjectItem.ProjectItems: this collection returns the children of the ProjectItem (be a folder or a file). It is used to navigate the hierarchy from top to bottom.

2) ProjectItem.Collection: this collection returns the collection of items the ProjectItem (be a folder or a file) belongs to. In particular, the ProjectItem.Collection.Parent property returns the parent of the ProjectItem. It is used to navigate the hierarchy from bottom to top.

It should be clear at this point that both collections are different and can not be the same.

SQL Server Database projects implement the automation model in the Microsoft.VisualStudio.Package.Automation. namespace of the Microsoft.VisualStudio.TeamSystem.DataPackage.dll package. In this namespace, there are two classes of interest:

1) OAProjectItem<T>

This class implements correctly the Collection property as follows:

public virtual ProjectItems get_Collection()
{
    HierarchyNode parent = this.node.Parent;
    if (parent is ProjectNode)
    {
        return ((OAProject) parent.GetAutomationObject()).ProjectItems;
    }
    if ((parent is FileNode) && (parent.FirstChild != null))
    {
        return ((OAProjectItem<FileNode>) parent.GetAutomationObject()).ProjectItems;
    }
    if (!(parent is FolderNode))
    {
        throw new NotImplementedException();
    }
    return ((OAProjectItem<FolderNode>) parent.GetAutomationObject()).ProjectItems;
}

Notice that it uses "parent" because the Collection property refers to the parent, not to the children.

2) OAFolderItem, which inherits from that class and overrides (incorrectly) the ProjectItems and Collection to return the same value!:

public override ProjectItems Collection
{
    get
    {
        return new OAProjectItems(base.Project, base.Node);
    }
}
 
public override ProjectItems ProjectItems
{
    get
    {
        return this.Collection;
    }
}
 
Notice that this implementation is absolutely wrong!
 

 




Sign in to post a comment.
Posted by Microsoft on 9/5/2007 at 7:01 PM
Thanks for your feedback. We have routed this issue to the appropriate group within the Visual Studio Product Team for triage and resolution.

Thank you,
Visual Studio Product Team.
Posted by Microsoft on 9/5/2007 at 5:19 PM
Thank you for your feedback. We are currently investigating. If this issue is urgent, please call support directly (see http://support.microsoft.com).

Thank you,
Visual Studio Product Team