Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,30 @@ private void AnalyzeClassDeclaration(SyntaxNodeAnalysisContext context) {
var classDeclaration = (ClassDeclarationSyntax)context.Node;

if (
!(
classDeclaration.BaseList?.Types.FirstOrDefault()?.Type
is GenericNameSyntax genericName &&
genericName.Identifier.ValueText.EndsWith("LogicBlock")
)
classDeclaration.BaseList?.Types.FirstOrDefault()?.Type is not GenericNameSyntax baseLogicBlock ||
!baseLogicBlock.Identifier.ValueText.EndsWith("LogicBlock")
) {
// Only analyze types that appear to be logic blocks.
return;
}

// We can't apply the LogicBlock attribute to generic LogicBlock types
// if one of the generics is the state type
if (
classDeclaration.TypeParameterList is not null
&& classDeclaration.TypeParameterList.Parameters.Count > 0
&& classDeclaration.TypeParameterList.Parameters.Any(
parameter =>
baseLogicBlock.TypeArgumentList.Arguments.Any(
argument =>
argument is IdentifierNameSyntax identifierArg
&& identifierArg.Identifier.ValueText == parameter.Identifier.ValueText
)
)
) {
return;
}

var attributes = classDeclaration.AttributeLists.SelectMany(
list => list.Attributes
).Where(
Expand Down