File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 3
3
// See the LICENSE file in the project root for more information.
4
4
5
5
using System . Diagnostics . CodeAnalysis ;
6
- using System . Linq ;
7
6
using Microsoft . CodeAnalysis ;
8
7
9
8
namespace CommunityToolkit . Mvvm . SourceGenerators . Extensions ;
@@ -26,8 +25,16 @@ internal static class SymbolInfoExtensions
26
25
/// </remarks>
27
26
public static bool TryGetAttributeTypeSymbol ( this SymbolInfo symbolInfo , [ NotNullWhen ( true ) ] out INamedTypeSymbol ? typeSymbol )
28
27
{
29
- if ( ( symbolInfo . Symbol ?? symbolInfo . CandidateSymbols . SingleOrDefault ( ) ) is not ISymbol attributeSymbol ||
30
- ( attributeSymbol as INamedTypeSymbol ?? attributeSymbol . ContainingType ) is not INamedTypeSymbol resultingSymbol )
28
+ ISymbol ? attributeSymbol = symbolInfo . Symbol ;
29
+
30
+ // If no symbol is selected and there is a single candidate symbol, use that
31
+ if ( attributeSymbol is null && symbolInfo . CandidateSymbols is [ ISymbol candidateSymbol ] )
32
+ {
33
+ attributeSymbol = candidateSymbol ;
34
+ }
35
+
36
+ // Extract the symbol from either the current one or the containing type
37
+ if ( ( attributeSymbol as INamedTypeSymbol ?? attributeSymbol ? . ContainingType ) is not INamedTypeSymbol resultingSymbol )
31
38
{
32
39
typeSymbol = null ;
33
40
You can’t perform that action at this time.
0 commit comments