dotnet / project-system

The .NET Project System for Visual Studio
MIT License
959 stars 386 forks source link

Avoid DTE construction where possible #9375

Closed drewnoakes closed 5 months ago

drewnoakes commented 5 months ago

This code is trying to access the UnconfiguredProject for a given IVsHierarchy.

It first attempts to cast the hierarchy to IVsBrowseObjectContext. It looks like the intention was then to use that if present, otherwise use DTE.

The code incorrectly checks for null (Nothing) to see if the first conversion failed, and only then try DTE. As it was written, it would only check DTE if the first conversion succeeded, meaning that both the first cast and the DTE approach have to work.

By fixing the null check, we avoid calling DTE in the common case.

There is only one caller of this private method and I've reviewed it for correctness.

Microsoft Reviewers: Open in CodeFlow