11using System ;
22using System . Collections . Concurrent ;
33using System . Linq ;
4+ using System . Runtime . InteropServices ;
45using System . Runtime . InteropServices . ComTypes ;
56
67namespace Rubberduck . Parsing . ComReflection . TypeLibReflection
@@ -15,14 +16,15 @@ namespace Rubberduck.Parsing.ComReflection.TypeLibReflection
1516 /// returned for each invocation, even for the same ProgID or ITypeInfo. That will cause problems later such
1617 /// as being unable to cast an instance from one type to another, even though they are based on exactly the
1718 /// same ProgID/ITypeInfo/etc.. In those cases, the <see cref="Type.IsEquivalentTo"/> incorrectly returns
18- /// false. Thus, those methods should be wrapped in the <see cref="TryCacheType"/ > methods to ensure that
19+ /// false. Thus, those methods should be wrapped in the <c>TryCachedType</c > methods to ensure that
1920 /// the repeated invocation will continue to return exactly same <see cref="Type"/>.
2021 ///
2122 /// For details on the issue with the <see cref="Type.IsEquivalentTo"/>, refer to:
2223 /// https://developercommunity.visualstudio.com/content/problem/422208/typeisequivalent-does-not-behave-according-to-the.html
2324 /// </remarks>
2425 public interface ICachedTypeService
2526 {
27+ bool TryInvalidate ( string project , string progId ) ;
2628 bool TryGetCachedType ( string progId , out Type type ) ;
2729 bool TryGetCachedType ( string project , string progId , out Type type ) ;
2830 bool TryGetCachedType ( ITypeInfo typeInfo , out Type type ) ;
@@ -160,5 +162,15 @@ private static bool TryGetValue(string project, string progId, out Type type)
160162 type = null ;
161163 return false ;
162164 }
165+
166+ public bool TryInvalidate ( string project , string progId )
167+ {
168+ if ( TypeCaches . TryGetValue ( project ? . ToLowerInvariant ( ) ?? string . Empty , out var cache ) )
169+ {
170+ return cache . Remove ( progId ) ;
171+ }
172+
173+ return false ;
174+ }
163175 }
164176}
0 commit comments