File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,27 @@ namespace Microsoft.VisualStudio.Shell.Interop
99 /// </summary>
1010 public static class IVsHierarchyExtensions
1111 {
12+ /// <summary>
13+ /// Tries to get a property from a hierarchy item.
14+ /// </summary>
15+ /// <remarks>
16+ /// Inspired by https://github.com/dotnet/roslyn/blob/main/src/VisualStudio/Core/Def/Implementation/ProjectSystem/Extensions/IVsHierarchyExtensions.cs
17+ /// </remarks>
18+ public static bool TryGetItemProperty < T > ( this IVsHierarchy hierarchy , uint itemId , int propertyId , out T ? value )
19+ {
20+ ThreadHelper . ThrowIfNotOnUIThread ( ) ;
21+
22+ if ( ErrorHandler . Failed ( hierarchy . GetProperty ( itemId , propertyId , out var property ) ) || ! ( property is T ) )
23+ {
24+ value = default ;
25+ return false ;
26+ }
27+
28+ value = ( T ) property ;
29+
30+ return true ;
31+ }
32+
1233 /// <summary>
1334 /// Converts an IVsHierarchy to a Project.
1435 /// </summary>
You can’t perform that action at this time.
0 commit comments