mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
30 lines
1.6 KiB
Plaintext
30 lines
1.6 KiB
Plaintext
<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #>
|
|
<#@ output extension=".cs" #>
|
|
<#@ assembly name="System.Core" #>
|
|
<#@ import namespace="Microsoft.Agents.ObjectModel" #>
|
|
<#@ include file="Snippets/AssignVariableTemplate.tt" once="true" #>
|
|
/// <summary>
|
|
/// Parses a string or untyped value to the provided data type. When the input is a string, it will be treated as JSON.
|
|
/// </summary>
|
|
internal sealed class <#= this.Name #>Executor(FormulaSession session) : ActionExecutor(id: "<#= this.Id #>", session)
|
|
{
|
|
// <inheritdoc />
|
|
protected override async ValueTask<object?> ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)
|
|
{
|
|
VariableType targetType = <#= this.GetVariableType() #>;<#
|
|
if (this.Model.Value.IsVariableReference && this.Model.Value.VariableReference.SegmentCount == 2)
|
|
{#>
|
|
object? parsedValue = await context.ConvertValueAsync(targetType, key: "<#= this.Model.Value.VariableReference.VariableName #>", scopeName: "<#= this.Model.Value.VariableReference.NamespaceAlias #>", cancellationToken).ConfigureAwait(false);<#
|
|
}
|
|
else if (this.Model.Value.IsVariableReference)
|
|
{#>
|
|
object? parsedValue = await context.ConvertValueAsync(targetType, <#= FormatStringValue(this.Model.Value.VariableReference.ToString()) #>, cancellationToken).ConfigureAwait(false);<#
|
|
}
|
|
else
|
|
{#>
|
|
object? parsedValue = await context.ConvertValueAsync(targetType, <#= FormatStringValue(this.Model.Value.ExpressionText) #>, cancellationToken).ConfigureAwait(false);<#
|
|
}
|
|
AssignVariable(this.Variable, "parsedValue"); #>
|
|
return default;
|
|
}
|
|
} |