Skip to main content

Preserving Additional Properties in C# v4 SDKs (Beta)

· One min read

C# v4 SDKs now keep the fields your specification does not name. Object models carry an AdditionalProperties bag, so an extra field in a response is no longer dropped, and you can send fields of your own the specification does not declare.

Details​

Object and allOf models now carry an AdditionalProperties bag, so a field the SDK does not model survives deserialization and is written back on serialization. When the schema types its additional values, the bag is AdditionalProperties<TValue>. Otherwise it holds the raw JSON and TryGetValue<T> deserializes an entry on demand. A schema that sets additionalProperties: false gets no bag. Keys are wire names.

Usage Example​

Read and send a field the specification does not name:

var customer = await client.Customers.GetCustomer(new GetCustomerRequest { CustomerId = "cus_123" });

if (customer.AdditionalProperties.TryGetValue<string>("loyalty_tier", out var tier))
{
Console.WriteLine($"Loyalty tier: {tier}");
}

var update = new CustomerUpdate { Email = "jane@example.com" };
update.AdditionalProperties.Set("loyalty_tier", "gold");

This feature is available in the C# v4 SDK (beta). Generate it from the APIMatic CLI:

apimatic sdk generate --language=csharp --codegen-version=v4 --stability=beta

For the full set of flags and options, see the APIMatic CLI documentation.