Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.25k stars 4.6k forks source link

ClientModel: Release `Azure.Variant` in the Azure.Core package #32978

Open heaths opened 1 year ago

heaths commented 1 year ago

Feature Description

Azure.Variant is an implementation of a tagged union. It provides a type we can use for both primitives and value types to avoid boxing .NET intrinsic types. For example, in libraries like KeyVault mentioned below, it could be used to hold both a string and an int without boxing the int.

API Proposal

https://github.com/dotnet/runtime/issues/28882

Additions we'd like to make

Libraries we expect to use it

christothes commented 1 year ago

Do we have any other context on the Azure.Value type?

heaths commented 1 year ago

@KrzysztofCwalina and @tg-msft asked me to consider using it for an upcoming KV release, but seems it won't make it in time. They asked me to open a tracking issue.

annelo-msft commented 1 year ago

Per @KrzysztofCwalina:

The following package GA is blocked on this. We want to not ship this type and use Value instead: https://apiview.dev/Assemblies/Review/e1389ac1af984a86a079127e8093937a#Azure.Communication.JobRouter.LabelValue

annelo-msft commented 1 year ago

Filling in some context:

heaths commented 1 year ago

KeyVaultSettingValue does do one thing a little differently than Value, and it may or may not be worth considering. To avoid polymorphic types for a single value, we recommended a type: string property for the value. Any primitive can encode as a string, so this avoided more complexity in the generated models we use as an HLC. Thus, ToString always returns the string-formatted value, and customers can set a string. This allows a customer on an older SDK version to read/write values that are added to the service, which are not part of the schema (the key/value pairs themselves).

Maybe Value is meant more for polymorphic types, but this might be something to consider. At least when I opened this tracking issue, Value did not support an everything-as-a-string fallback.

annelo-msft commented 1 year ago

A service team has asked how they can indicate in a swagger or typespec file that Value should be used in a model - it would be good to provide a solution to this.

annelo-msft commented 6 months ago

@KrzysztofCwalina, we should touch-base on whether or not this is currently a priority, and if so, what our approach is now given System.ClientModel