// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System.Collections.Generic; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using CommunityToolkit.Mvvm.SourceGenerators.Extensions; namespace CommunityToolkit.Mvvm.SourceGenerators; /// public sealed partial class ObservableValidatorValidateAllPropertiesGenerator { /// /// An that selects candidate nodes to process. /// private sealed class SyntaxReceiver : ISyntaxContextReceiver { /// /// The list of info gathered during exploration. /// private readonly List gatheredInfo = new(); /// /// Gets the collection of gathered info to process. /// public IReadOnlyCollection GatheredInfo => this.gatheredInfo; /// public void OnVisitSyntaxNode(GeneratorSyntaxContext context) { if (context.Node is ClassDeclarationSyntax classDeclaration && context.SemanticModel.GetDeclaredSymbol(classDeclaration) is INamedTypeSymbol { IsGenericType: false } classSymbol && context.SemanticModel.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservableValidator") is INamedTypeSymbol validatorSymbol && classSymbol.InheritsFrom(validatorSymbol)) { this.gatheredInfo.Add(classSymbol); } } } }