2022-09-06 00:47:58 +03:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2022-09-06 01:14:31 +03:00
|
|
|
using BlueWest.EfMethods.Sources;
|
2022-09-06 00:47:58 +03:00
|
|
|
using Microsoft.CodeAnalysis;
|
|
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
|
2022-09-06 01:14:31 +03:00
|
|
|
namespace BlueWest.EfMethods
|
2022-09-06 00:47:58 +03:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|