1
0
Fork 0
Questionable/QuestPathGenerator/RoslynElements/ExcelRefExtensions.cs

31 lines
1.2 KiB
C#
Raw Permalink Normal View History

2024-08-17 18:59:42 +00:00
using System;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Questionable.Model.Questing;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
using static Questionable.QuestPathGenerator.RoslynShortcuts;
namespace Questionable.QuestPathGenerator.RoslynElements;
internal static class ExcelRefExtensions
{
public static ExpressionSyntax ToExpressionSyntax(this ExcelRef excelRef)
{
if (excelRef.Type == ExcelRef.EType.Key)
return ObjectCreationExpression(
IdentifierName(nameof(ExcelRef)))
.WithArgumentList(
ArgumentList(
SingletonSeparatedList(
Argument(LiteralValue(excelRef.AsKey())))));
else if (excelRef.Type == ExcelRef.EType.RowId)
return ObjectCreationExpression(
IdentifierName(nameof(ExcelRef)))
.WithArgumentList(
ArgumentList(
SingletonSeparatedList(
Argument(LiteralValue(excelRef.AsRowId())))));
else
throw new Exception($"Unsupported ExcelRef type {excelRef.Type}");
}
}