Questionable/QuestPathGenerator/RoslynElements/GatheringNodeExtensions.cs

30 lines
1.3 KiB
C#
Raw Permalink Normal View History

2024-08-17 18:59:42 +00:00
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Questionable.Model.Gathering;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
using static Questionable.QuestPathGenerator.RoslynShortcuts;
namespace Questionable.QuestPathGenerator.RoslynElements;
internal static class GatheringNodeExtensions
{
public static ExpressionSyntax ToExpressionSyntax(this GatheringNode gatheringNode)
{
var emptyLocation = new GatheringNode();
return ObjectCreationExpression(
IdentifierName(nameof(GatheringNode)))
.WithInitializer(
InitializerExpression(
SyntaxKind.ObjectInitializerExpression,
SeparatedList<ExpressionSyntax>(
SyntaxNodeList(
Assignment(nameof(GatheringNode.DataId), gatheringNode.DataId,
emptyLocation.DataId)
.AsSyntaxNodeOrToken(),
Assignment(nameof(GatheringNode.Fly), gatheringNode.Fly, emptyLocation.Fly)
.AsSyntaxNodeOrToken(),
AssignmentList(nameof(GatheringNode.Locations), gatheringNode.Locations)
.AsSyntaxNodeOrToken()))));
}
}