Skip to content

Commit 9ba450e

Browse files
author
Gunpal Jain
committed
suppressed IL2026, IL3050 for Reflection based type resolver
1 parent 45eaf37 commit 9ba450e

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/libs/CSharpToJsonSchema/MeaiFunction.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ public MeaiFunction(Tool tool, Func<string, CancellationToken, Task<string>> cal
6262
}
6363

6464

65-
#pragma warning disable IL2026, IL3050 // Reflection is used only when enabled
65+
6666
private JsonSerializerOptions InitializeReflectionOptions()
6767
{
68+
#pragma warning disable IL2026, IL3050 // Reflection is used only when enabled
6869
if(!JsonSerializer.IsReflectionEnabledByDefault)
6970
throw new InvalidOperationException("JsonSerializer.IsReflectionEnabledByDefault is false, please pass in a JsonSerializerOptions instance.");
7071

@@ -77,8 +78,9 @@ private JsonSerializerOptions InitializeReflectionOptions()
7778
TypeInfoResolver = new DefaultJsonTypeInfoResolver()
7879
};
7980
return _options;
80-
}
8181
#pragma warning restore IL2026, IL3050 // Reflection is used only when enabled
82+
}
83+
8284

8385
/// <summary>
8486
/// Invokes the tool with the given arguments asynchronously.
@@ -134,25 +136,27 @@ protected virtual string GetArgsString(IEnumerable<KeyValuePair<string, object?>
134136
}
135137
else
136138
{
137-
var type = args.Value?.GetType();
138-
if(type.IsPrimitive)
139-
{
140-
jsonObject[args.Key] = JsonValue.Create(args.Value);
141-
}
142-
else
143-
{
139+
var type = args.Value?.GetType();
140+
// if(type.IsPrimitive)
141+
// {
142+
// jsonObject[args.Key] = JsonValue.Create(args.Value);
143+
// }
144+
// else
145+
// {
144146
if (_options == null)
145147
{
148+
#pragma warning disable IL2026, IL3050 // Reflection is used only when enabled
146149
//Fallback to Reflection
147150
//This will break the AOT, Hoping for the best, IChatClient implementation only send JSON classes
148151
//Or Developer is using the code generator
149152
_options = InitializeReflectionOptions();
153+
#pragma warning disable IL2026, IL3050 // Reflection is used only when enabled
150154
}
151155
var typeInfo = _options.GetTypeInfo(type);
152156

153157
var str = JsonSerializer.Serialize(args.Value, typeInfo);
154158
jsonObject[args.Key] = JsonNode.Parse(str);
155-
}
159+
//}
156160
}
157161
}
158162

src/libs/CSharpToJsonSchema/TypeToSchemaHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static OpenApiSchema AsJsonSchema(
5252
JsonSerializerOptions? options = null)
5353
{
5454
type = type ?? throw new ArgumentNullException(nameof(type));
55-
#pragma warning disable IL2026
55+
#pragma warning disable IL2026, IL3050
5656
var node = new JsonSerializerOptions
5757
{
5858
TypeInfoResolver = jsonTypeInfoResolver ?? new DefaultJsonTypeInfoResolver(),
@@ -61,7 +61,7 @@ public static OpenApiSchema AsJsonSchema(
6161
TransformSchemaNode = (context, node) => node,
6262
TreatNullObliviousAsNonNullable = true,
6363
});
64-
#pragma warning restore IL2026
64+
#pragma warning restore IL2026, IL3050
6565
var schema = Create(type, strict);
6666
if (schema.Type == "object")
6767
{

0 commit comments

Comments
 (0)