Files
agent-framework/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Extensions/TemplateExtensions.cs
T
Ben Thomas 647db9635a .NET: Rename workflows projects (#975)
* Renaming Microsoft.Agent.Workflows to Microsoft.Agents.AI.Workflows

* Removing local settings.

* Removing remining old files from merge.
2025-09-29 18:30:45 +00:00

43 lines
1.4 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System.Collections.Generic;
using System.Linq;
using Microsoft.Bot.ObjectModel;
using Microsoft.PowerFx;
namespace Microsoft.Agents.AI.Workflows.Declarative.Extensions;
internal static class TemplateExtensions
{
public static string Format(this RecalcEngine engine, IEnumerable<TemplateLine> template) =>
string.Concat(template.Select(engine.Format));
public static string Format(this RecalcEngine engine, TemplateLine? line) =>
line is not null ?
string.Concat(line.Segments.Select(engine.Format)) :
string.Empty;
public static string Format(this RecalcEngine engine, TemplateSegment segment)
{
if (segment is TextSegment textSegment)
{
return textSegment.Value ?? string.Empty;
}
if (segment is ExpressionSegment { Expression: not null } expressionSegment)
{
if (expressionSegment.Expression.ExpressionText is not null)
{
return engine.Eval(expressionSegment.Expression.ExpressionText).Format();
}
if (expressionSegment.Expression.VariableReference is not null)
{
return engine.Eval(expressionSegment.Expression.VariableReference.ToString()).Format();
}
}
throw new DeclarativeModelException($"Unsupported segment type: {segment.GetType().Name}");
}
}