mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
[BREAKING] Obsoleting ReflectingExecutor in favor of source gen (#3380)
* Initial working version with tests.
* Updates to validate class data once instead of for each handler method. Also updated Diagnostics Ids to format of MAFGENWF{NUM}
* Formatting and trying to fix generation project pack.
* Another atempt at getting the genrators project to build.
* More attempts to fix generator build and pack.
* Fixing file encodings.
* Initail round of cleanup.
* Trying to fix packing.
* Still trying to fix pipeline pack.
* Remove obsolescence markers, sample updates, and docs from generator branch.
This commit separates the generator core functionality from the
deprecation of ReflectingExecutor. The removed changes will be
re-added in a dependent branch (wf-obsolete-reflector).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Mark ReflectingExecutor and IMessageHandler as obsolete.
This commit deprecates the reflection-based handler discovery approach
in favor of the new [MessageHandler] attribute with source generation.
Changes:
- Add [Obsolete] to ReflectingExecutor<T>, IMessageHandler<T>, IMessageHandler<T,R>
- Add #pragma to suppress warnings in internal reflection code
- Update Concurrent sample to use new [MessageHandler] pattern
- Add Directory.Build.props for samples to include generator
- Add documentation files explaining the migration
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Obsoleteing Reflector-based workflow code generation in favor of Source Generators and updating some samples to use new pattern.
This commit deprecates the reflection-based handler discovery approach
in favor of the new [MessageHandler] attribute with source generation.
Changes:
- Add [Obsolete] to ReflectingExecutor<T>, IMessageHandler<T>, IMessageHandler<T,R>
- Add #pragma to suppress warnings in internal reflection code
- Update Concurrent sample to use new [MessageHandler] pattern
- Add Directory.Build.props for samples to include generator
- Add documentation files explaining the migration
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Cleaning up temporary design and progress files.
---------
Co-authored-by: alliscode <bentho@microsoft.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
alliscode
Chris
parent
5e565dbec0
commit
907654a489
@@ -0,0 +1,121 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace Microsoft.Agents.AI.Workflows.Generators.Models;
|
||||
|
||||
/// <summary>
|
||||
/// A wrapper around <see cref="ImmutableArray{T}"/> that provides value-based equality.
|
||||
/// This is necessary for incremental generator caching since ImmutableArray uses reference equality.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Creates a new <see cref="EquatableArray{T}"/> from an <see cref="ImmutableArray{T}"/>.
|
||||
/// </remarks>
|
||||
internal readonly struct EquatableArray<T>(ImmutableArray<T> array) : IEquatable<EquatableArray<T>>, IEnumerable<T>
|
||||
where T : IEquatable<T>
|
||||
{
|
||||
private readonly ImmutableArray<T> _array = array.IsDefault ? ImmutableArray<T>.Empty : array;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying array.
|
||||
/// </summary>
|
||||
public ImmutableArray<T> AsImmutableArray() => this._array;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of elements in the array.
|
||||
/// </summary>
|
||||
public int Length => this._array.Length;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the element at the specified index.
|
||||
/// </summary>
|
||||
public T this[int index] => this._array[index];
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the array is empty.
|
||||
/// </summary>
|
||||
public bool IsEmpty => this._array.IsEmpty;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(EquatableArray<T> other)
|
||||
{
|
||||
if (this._array.Length != other._array.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < this._array.Length; i++)
|
||||
{
|
||||
if (!this._array[i].Equals(other._array[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is EquatableArray<T> other && this.Equals(other);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
if (this._array.IsEmpty)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var hashCode = 17;
|
||||
foreach (var item in this._array)
|
||||
{
|
||||
hashCode = hashCode * 31 + (item?.GetHashCode() ?? 0);
|
||||
}
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable<T>)this._array).GetEnumerator();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return this.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Equality operator.
|
||||
/// </summary>
|
||||
public static bool operator ==(EquatableArray<T> left, EquatableArray<T> right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inequality operator.
|
||||
/// </summary>
|
||||
public static bool operator !=(EquatableArray<T> left, EquatableArray<T> right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an empty <see cref="EquatableArray{T}"/>.
|
||||
/// </summary>
|
||||
public static EquatableArray<T> Empty => new(ImmutableArray<T>.Empty);
|
||||
|
||||
/// <summary>
|
||||
/// Implicit conversion from <see cref="ImmutableArray{T}"/>.
|
||||
/// </summary>
|
||||
public static implicit operator EquatableArray<T>(ImmutableArray<T> array) => new(array);
|
||||
}
|
||||
Reference in New Issue
Block a user