88#pragma warning disable SA1111  // Closing parenthesis should be on line of last parameter 
99#pragma warning disable SA1112  // Closing parenthesis should be on line of opening parenthesis 
1010#pragma warning disable SA1114  // Parameter list should follow declaration 
11+ #pragma warning disable S3358  // Extract this nested ternary operation into an independent statement. 
12+ #pragma warning disable S1067  // Expressions should not be too complex 
13+ #pragma warning disable S4039  // Make 'AIFunctionArguments' sealed 
14+ #pragma warning disable CA1033  // Make 'AIFunctionArguments' sealed 
1115#pragma warning disable CA1710  // Identifiers should have correct suffix 
1216
1317namespace  Microsoft . Extensions . AI ; 
@@ -20,15 +24,16 @@ namespace Microsoft.Extensions.AI;
2024/// an <see cref="AIFunction"/> if it needs to resolve any services from a dependency injection 
2125/// container. 
2226/// </remarks> 
23- public  sealed   class  AIFunctionArguments  :  IDictionary < string ,  object ? > ,  IReadOnlyDictionary < string ,  object ? > 
27+ public  class  AIFunctionArguments  :  IDictionary < string ,  object ? > ,  IReadOnlyDictionary < string ,  object ? > 
2428{ 
2529    /// <summary>The nominal arguments.</summary> 
2630    private  readonly  Dictionary < string ,  object ? >  _arguments ; 
2731
28-     /// <summary>Initializes a new instance of the <see cref="AIFunctionArguments"/> class.</summary> 
32+     /// <summary>Initializes a new instance of the <see cref="AIFunctionArguments"/> class, and uses the default comparer for key comparisons.</summary> 
33+     /// <remarks>The <see cref="IEqualityComparer{T}"/> is ordinal by default.</remarks> 
2934    public  AIFunctionArguments ( ) 
35+         :  this ( null ,  null ) 
3036    { 
31-         _arguments  =  [ ] ; 
3237    } 
3338
3439    /// <summary> 
@@ -42,14 +47,44 @@ public AIFunctionArguments()
4247    /// operations on this instance will be routed directly to that instance. If <paramref name="arguments"/> 
4348    /// is not a dictionary, a shallow clone of its data will be used to populate this 
4449    /// instance. A <see langword="null"/> <paramref name="arguments"/> is treated as an 
45-     /// empty dictionary. 
50+     /// empty parameters dictionary. 
51+     /// The <see cref="IEqualityComparer{T}"/> is ordinal by default. 
4652    /// </remarks> 
4753    public  AIFunctionArguments ( IDictionary < string ,  object ? > ?  arguments ) 
54+         :  this ( arguments ,  null ) 
55+     { 
56+     } 
57+ 
58+     /// <summary>Initializes a new instance of the <see cref="AIFunctionArguments"/> class.</summary> 
59+     /// <param name="comparer">The <see cref="IEqualityComparer{T}"/> to use for key comparisons.</param> 
60+     public  AIFunctionArguments ( IEqualityComparer < string > ?  comparer ) 
61+         :  this ( null ,  comparer ) 
62+     { 
63+     } 
64+ 
65+     /// <summary> 
66+     /// Initializes a new instance of the <see cref="AIFunctionArguments"/> class containing 
67+     /// the specified <paramref name="arguments"/>. 
68+     /// </summary> 
69+     /// <param name="arguments">The arguments represented by this instance.</param> 
70+     /// <param name="comparer">The <see cref="IEqualityComparer{T}"/> to be used.</param> 
71+     /// <remarks> 
72+     /// The <paramref name="arguments"/> reference will be stored if the instance is already a 
73+     /// <see cref="Dictionary{TKey, TValue}"/> with the same <see cref="IEqualityComparer{T}"/> or if 
74+     /// <paramref name="arguments"/> is <see langword="null" /> in which case all dictionary operations 
75+     /// on this instance will be routed directly to that instance otherwise a shallow clone of the provided <paramref name="arguments"/>. 
76+     /// A <see langword="null"/> <paramref name="arguments"/> is will be treated as an empty parameters dictionary. 
77+     /// </remarks> 
78+     public  AIFunctionArguments ( IDictionary < string ,  object ? > ?  arguments ,  IEqualityComparer < string > ?  comparer ) 
4879    { 
80+ #pragma warning disable S1698  // Consider using 'Equals' if value comparison is intended. 
4981        _arguments  = 
50-             arguments  is  null  ?  [ ]  : 
51-             arguments  as  Dictionary < string ,  object ? >  ?? 
52-             new  Dictionary < string ,  object ? > ( arguments ) ; 
82+             arguments  is  null 
83+                 ?  new  Dictionary < string ,  object ? > ( comparer ) 
84+                 :  ( arguments  is  Dictionary < string ,  object ? >  dc )  &&  ( comparer  is  null  ||  dc . Comparer  ==  comparer ) 
85+                     ?  dc 
86+                     :  new  Dictionary < string ,  object ? > ( arguments ,  comparer ) ; 
87+ #pragma warning restore S1698  // Consider using 'Equals' if value comparison is intended. 
5388    } 
5489
5590    /// <summary>Gets or sets services optionally associated with these arguments.</summary> 
0 commit comments