// Copyright (c) Microsoft. All rights reserved. using System; namespace Microsoft.Agents.AI.Workflows; /// /// Event triggered when a workflow executor yields output. /// public sealed class WorkflowOutputEvent : WorkflowEvent { internal WorkflowOutputEvent(object data, string sourceId) : base(data) { this.SourceId = sourceId; } /// /// The unique identifier of the executor that yielded this output. /// public string SourceId { get; } /// /// Determines whether the underlying data is of the specified type or a derived type. /// /// The type to compare with the type of the underlying data. /// true if the underlying data is assignable to type T; otherwise, false. public bool Is() => this.IsType(typeof(T)); /// /// Determines whether the underlying data is of the specified type or a derived type. /// /// The type to compare with the type of the underlying data. /// true if the underlying data is assignable to type T; otherwise, false. public bool IsType(Type type) => this.Data is { } data && type.IsInstanceOfType(data); /// /// Attempts to retrieve the underlying data as the specified type. /// /// The type to which to cast. /// The value of Data as to the target type. public T? As() => this.Data is T value ? value : default; /// /// Attempts to retrieve the underlying data as the specified type. /// /// The type to which to cast. /// The value of Data as to the target type. public object? AsType(Type type) => this.IsType(type) ? this.Data : null; }