From 4deee5714022807c1dfb999c2661c8bf90fbe1e2 Mon Sep 17 00:00:00 2001 From: Amadeusz Sadowski Date: Fri, 23 Oct 2020 15:54:18 +0200 Subject: [PATCH] feat: ListNode.WithNode overrides cov-returns closes #73 --- .../Generators/ListNodePartialGenerator.cs | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/WarHub.ArmouryModel.Source.CodeGeneration/Generators/ListNodePartialGenerator.cs b/src/WarHub.ArmouryModel.Source.CodeGeneration/Generators/ListNodePartialGenerator.cs index ecff0ea..acc2551 100644 --- a/src/WarHub.ArmouryModel.Source.CodeGeneration/Generators/ListNodePartialGenerator.cs +++ b/src/WarHub.ArmouryModel.Source.CodeGeneration/Generators/ListNodePartialGenerator.cs @@ -187,33 +187,21 @@ private MemberDeclarationSyntax AcceptGenericMethod() private MemberDeclarationSyntax CreateWithNodesMethod() { - const string NodesVarName = "nodes"; + var nodes = IdentifierName("nodes"); + var nodeList = Descriptor.GetNodeTypeIdentifierName().ToNodeListType(); + var listNode = IdentifierName(Descriptor.GetListNodeTypeName()); return - MethodDeclaration( - GenericName(Names.ListNode) - .AddTypeArgumentListArguments( - Descriptor.GetNodeTypeIdentifierName()), - Names.WithNodes) - .AddModifiers( - SyntaxKind.PublicKeyword, - SyntaxKind.OverrideKeyword) + MethodDeclaration(listNode, Names.WithNodes) + .AddModifiers(SyntaxKind.PublicKeyword, SyntaxKind.OverrideKeyword) .AddParameterListParameters( - Parameter( - Identifier(NodesVarName)) - .WithType( - Descriptor.GetNodeTypeIdentifierName().ToNodeListType())) + Parameter(nodes.Identifier) + .WithType(nodeList)) .AddBodyStatements( ReturnStatement( ConditionalExpression( - BinaryExpression( - SyntaxKind.EqualsExpression, - ThisExpression().Dot(IdentifierName(Names.NodeList)), - IdentifierName(NodesVarName)), + ThisExpression().Dot(IdentifierName(Names.NodeList)).OpEquals(nodes), ThisExpression(), - IdentifierName(NodesVarName) - .Dot( - IdentifierName(Names.ToListNode)) - .Invoke()))); + nodes.Dot(IdentifierName(Names.ToListNode)).Invoke()))); } } }