2021-12-24 20:06:06 +03:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using MapTo.Sources;
|
|
|
|
|
using Microsoft.CodeAnalysis;
|
|
|
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
|
|
|
|
|
|
namespace MapTo
|
|
|
|
|
{
|
|
|
|
|
internal class MapToSyntaxReceiver : ISyntaxReceiver
|
|
|
|
|
{
|
|
|
|
|
public List<TypeDeclarationSyntax> CandidateTypes { get; } = new();
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
|
|
|
|
|
{
|
|
|
|
|
if (syntaxNode is not TypeDeclarationSyntax { AttributeLists: { Count: >= 1 } attributes } typeDeclarationSyntax)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var attributeSyntax = attributes
|
|
|
|
|
.SelectMany(a => a.Attributes)
|
2022-08-18 18:48:44 +03:00
|
|
|
|
.FirstOrDefault(a => a.Name is
|
2021-12-24 20:06:06 +03:00
|
|
|
|
IdentifierNameSyntax { Identifier: { ValueText: MapFromAttributeSource.AttributeName } } // For: [MapFrom]
|
|
|
|
|
or
|
|
|
|
|
QualifiedNameSyntax // For: [MapTo.MapFrom]
|
|
|
|
|
{
|
|
|
|
|
Left: IdentifierNameSyntax { Identifier: { ValueText: Constants.RootNamespace } },
|
|
|
|
|
Right: IdentifierNameSyntax { Identifier: { ValueText: MapFromAttributeSource.AttributeName } }
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (attributeSyntax is not null)
|
|
|
|
|
{
|
|
|
|
|
CandidateTypes.Add(typeDeclarationSyntax);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-19 10:55:47 +03:00
|
|
|
|
}
|