Files
agent-framework/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Extensions/TemplateExtensions.cs
T
75a8335af5 .NET - [Breaking]: Update Declarative Object Model + Dependencies (#3017)
* Builds locally and tests pass

* Fix typo

* Reverted nuget config change to remove internal feed and map to new public object model package with renames.

* Renaming Bot object model in additional sample.

---------

Co-authored-by: Peter Ibekwe <peibekwe@microsoft.com>
2026-01-28 20:00:37 +00:00

43 lines
1.4 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System.Collections.Generic;
using System.Linq;
using Microsoft.Agents.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}");
}
}