mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
647db9635a
* Renaming Microsoft.Agent.Workflows to Microsoft.Agents.AI.Workflows * Removing local settings. * Removing remining old files from merge.
43 lines
1.4 KiB
C#
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}");
|
|
}
|
|
}
|