Open joshuaflanagan opened 4 months ago
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
ShipEngine/Models/Dto/CreateLabelFromShipmentDetails/StringEnum.cs | 41 | 53 | 77.36% | ||
<!-- | Total: | 46 | 58 | 79.31% | --> |
Totals | |
---|---|
Change from base Build 9486504073: | -1.1% |
Covered Lines: | 690 |
Relevant Lines: | 793 |
I would like to get rid of using C# enums in the SDK. They unnecessarily constrain the values that a user can send to the ShipEngine API. The API expects a string, the SDK should allow the user to specify a string. An enum requires converting values to an integer, which has no value for our purposes. It also leads to awkwardness when the default is
0
, which will correspond to an enum value we don't necessarily want. It requires the user to update their SDK any time there is a new possible value accepted by the API. We can still provide guidance for valid values via classes that expose static strings.However, there is likely code in the wild where users are setting properties to an enum value. This is an experiment to demonstrate using implicit conversion operators, and a custom JsonConverter, to allow a user to set a "string enum" value using a string or an enum.