.NET: Added support for polymorphic type as workflow output (#4485)

* Added support for polymorphic type as workflow output

* Update Linq expression to avoid unnecessary allocations.

* Added caching as per PR comment
This commit is contained in:
Peter Ibekwe
2026-03-10 12:45:01 -07:00
committed by GitHub
Unverified
parent 09b3e2e4f0
commit a3bfad4791
2 changed files with 296 additions and 1 deletions
@@ -3,6 +3,7 @@
#pragma warning disable CS0618 // Type or member is obsolete - Internal use of obsolete types for backward compatibility
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@@ -133,7 +134,25 @@ internal sealed class ExecutorProtocol(MessageRouter router, ISet<Type> sendType
public bool CanHandle(Type type) => router.CanHandle(type);
public bool CanOutput(Type type) => this._yieldTypes.Contains(new(type));
private readonly ConcurrentDictionary<Type, bool> _canOutputCache = new();
public bool CanOutput(Type type)
{
return this._canOutputCache.GetOrAdd(type, this.CanOutputCore);
}
private bool CanOutputCore(Type type)
{
foreach (TypeId yieldType in this._yieldTypes)
{
if (yieldType.IsMatchPolymorphic(type))
{
return true;
}
}
return false;
}
public ProtocolDescriptor Describe() => new(this.Router.IncomingTypes, yieldTypes, sendTypes, this.Router.HasCatchAll);
}