53 lines
1.6 KiB
C#
53 lines
1.6 KiB
C#
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using MapTo.Sources;
|
||
|
using Microsoft.CodeAnalysis;
|
||
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||
|
|
||
|
namespace MapTo
|
||
|
{
|
||
|
internal enum EfMethodsAttributeType
|
||
|
{
|
||
|
Add,
|
||
|
Update,
|
||
|
Invalid
|
||
|
}
|
||
|
|
||
|
internal record CandidateMember(
|
||
|
MemberDeclarationSyntax MemberDeclarationSyntax,
|
||
|
EfMethodsAttributeType AttributeType
|
||
|
);
|
||
|
|
||
|
|
||
|
internal class EfMethodsSyntaxReceiver : 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)
|
||
|
.FirstOrDefault(a => a.Name is
|
||
|
IdentifierNameSyntax { Identifier: { ValueText: EfGeneratorAttributeSource.AttributeName } }
|
||
|
or
|
||
|
QualifiedNameSyntax
|
||
|
{
|
||
|
Left: IdentifierNameSyntax { Identifier: { ValueText: Constants.RootNamespace } },
|
||
|
Right: IdentifierNameSyntax { Identifier: { ValueText: EfGeneratorAttributeSource.AttributeName } }
|
||
|
}
|
||
|
);
|
||
|
|
||
|
if (attributeSyntax is not null)
|
||
|
{
|
||
|
CandidateTypes.Add(typeDeclarationSyntax);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|