# TraconGeneratedToolArguments

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.tracongeneratedtoolarguments/
> Summary: TraconGeneratedToolArguments: The helper methods called by tool wrappers produced by the source generator while converting JSON arguments to CLR types.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Abstractions.dll</code></div>

The helper methods called by tool wrappers produced by the source
generator while converting JSON arguments to CLR types.

```csharp
public static class TraconGeneratedToolArguments
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.tracongeneratedtoolarguments/">TraconGeneratedToolArguments</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Remarks

This class is designed to be called only by code generated by the
`[TraconTool]` generator; calling it by hand is not a supported
scenario. The only reason it is public is that the generated code lives
in the consumer's own assembly and therefore needs to reach this type from outside this compilation.

No conversion **uses reflection**: everything works through
[JsonElement](https://learn.microsoft.com/dotnet/api/system.text.json.jsonelement)'s type-specific `Get*` methods or through
the converter delegate the caller supplies.

## Methods

### <a id="Tracon_TraconGeneratedToolArguments_GetArray__1_Microsoft_Extensions_AI_AIFunctionArguments_System_String_System_Func_System_Text_Json_JsonElement___0__System_Boolean_System_Collections_Generic_IReadOnlyList___0__"></a> GetArray<T\>\(AIFunctionArguments, string, Func<JsonElement, T\>, bool, IReadOnlyList<T\>?\)

Reads an array argument; each element is converted with the same converter.

```csharp
public static IReadOnlyList<T> GetArray<T>(AIFunctionArguments arguments, string name, Func<JsonElement, T> convert, bool required, IReadOnlyList<T>? defaultValue)
```

#### Parameters

`arguments` AIFunctionArguments

The call's arguments.

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The argument's JSON key.

`convert` [Func](https://learn.microsoft.com/dotnet/api/system.func\-2)<[JsonElement](https://learn.microsoft.com/dotnet/api/system.text.json.jsonelement), T\>

The converter that converts each element.

`required` [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

Whether to throw if the argument is missing.

`defaultValue` [IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<T\>?

The value to use if `required` is [false](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool)
and the argument is missing. An empty list is used if [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

#### Returns

 [IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<T\>

The converted array.

#### Type Parameters

`T` 

The array element type.

#### Exceptions

 [TraconException](/api/tracon.traconexception/)

The argument is required but missing, or the given value is not a JSON array.

### <a id="Tracon_TraconGeneratedToolArguments_GetOptional__1_Microsoft_Extensions_AI_AIFunctionArguments_System_String_System_Func_System_Text_Json_JsonElement___0____0_"></a> GetOptional<T\>\(AIFunctionArguments, string, Func<JsonElement, T\>, T\)

Reads an optional argument; returns the given default if missing.

```csharp
public static T GetOptional<T>(AIFunctionArguments arguments, string name, Func<JsonElement, T> convert, T defaultValue)
```

#### Parameters

`arguments` AIFunctionArguments

The call's arguments.

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The argument's JSON key.

`convert` [Func](https://learn.microsoft.com/dotnet/api/system.func\-2)<[JsonElement](https://learn.microsoft.com/dotnet/api/system.text.json.jsonelement), T\>

The converter that turns a [JsonElement](https://learn.microsoft.com/dotnet/api/system.text.json.jsonelement) into `T`.

`defaultValue` T

The value to use if the argument is missing.

#### Returns

 T

The converted value, or `defaultValue`.

#### Type Parameters

`T` 

The target CLR type.

#### Exceptions

 [TraconException](/api/tracon.traconexception/)

The argument was given but is an unexpected CLR type.

### <a id="Tracon_TraconGeneratedToolArguments_GetRequired__1_Microsoft_Extensions_AI_AIFunctionArguments_System_String_System_Func_System_Text_Json_JsonElement___0__"></a> GetRequired<T\>\(AIFunctionArguments, string, Func<JsonElement, T\>\)

Reads a required argument; throws if missing.

```csharp
public static T GetRequired<T>(AIFunctionArguments arguments, string name, Func<JsonElement, T> convert)
```

#### Parameters

`arguments` AIFunctionArguments

The call's arguments.

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The argument's JSON key.

`convert` [Func](https://learn.microsoft.com/dotnet/api/system.func\-2)<[JsonElement](https://learn.microsoft.com/dotnet/api/system.text.json.jsonelement), T\>

The converter that turns a [JsonElement](https://learn.microsoft.com/dotnet/api/system.text.json.jsonelement) into `T`.

#### Returns

 T

The converted value.

#### Type Parameters

`T` 

The target CLR type.

#### Exceptions

 [TraconException](/api/tracon.traconexception/)

The argument is missing, or is an unexpected CLR type.
