Files
agent-framework/dotnet/src/Microsoft.Agents.AI.Workflows/Checkpointing/ExecutorIdentityConverter.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

39 lines
1.2 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
using Microsoft.Agents.AI.Workflows.Execution;
namespace Microsoft.Agents.AI.Workflows.Checkpointing;
/// <summary>
/// Provides support for using <see cref="ExecutorIdentity"/> values as dictionary keys when serializing and deserializing JSON.
/// </summary>
internal sealed class ExecutorIdentityConverter() : JsonConverterDictionarySupportBase<ExecutorIdentity>
{
protected override JsonTypeInfo<ExecutorIdentity> TypeInfo
=> WorkflowsJsonUtilities.JsonContext.Default.ExecutorIdentity;
protected override ExecutorIdentity Parse(string propertyName)
{
if (propertyName.Length == 0)
{
return ExecutorIdentity.None;
}
if (propertyName[0] == '@')
{
return new() { Id = propertyName.Substring(1) };
}
throw new JsonException($"Invalid ExecutorIdentity key Expecting empty string or a value that is prefixed with '@'. Got '{propertyName}'");
}
protected override string Stringify(ExecutorIdentity value)
{
return value == ExecutorIdentity.None
? string.Empty
: $"@{value.Id}";
}
}