PandaTech.BaseConverter
1.0.7
See the version list below for details.
dotnet add package PandaTech.BaseConverter --version 1.0.7
NuGet\Install-Package PandaTech.BaseConverter -Version 1.0.7
<PackageReference Include="PandaTech.BaseConverter" Version="1.0.7" />
paket add PandaTech.BaseConverter --version 1.0.7
#r "nuget: PandaTech.BaseConverter, 1.0.7"
// Install PandaTech.BaseConverter as a Cake Addin #addin nuget:?package=PandaTech.BaseConverter&version=1.0.7 // Install PandaTech.BaseConverter as a Cake Tool #tool nuget:?package=PandaTech.BaseConverter&version=1.0.7
Base Converter
This project provides a class called PandaBaseConverter that can convert a number from base 10 to base 36 and vice versa. This project is available as a NuGet package as well.
Usage
Base 10 to Base 36
To convert a number from base 10 to base 36, call the Base10ToBase36 method, passing in the number as a long
long number = 12345;
string base36Number = BaseConverter.Base10ToBase36(number);
The resulting base36Number will be a string representation of the number in base 36.
Base 36 to Base 10
To convert a number from base 36 to base 10, call the Base36ToBase10 method, passing in the number as a string:
string base36Number = "2n9";
long number = BaseConverter.Base36ToBase10(base36Number);
The resulting number will be the decimal representation of the number in base 36.
Using in DTOs
public class MyDto
{
[JsonConverter(typeof(PandaJsonBaseConverter))]
public long Id { get; set; }
}
Using in controllers
[HttpGet("{id}")]
public async Task<ActionResult<MyDto>> Get([PandaJsonBaseConverter] long id)
{
var myDto = await _myService.Get(id);
return Ok(myDto);
}
In this case we will work in code with Id as long, but in json it will be as base 36 string.
Configuration
By default, the PandaBaseConverter class uses the characters "0123456789abcdefghijklmnopqrstuvwxyz" for base 36 conversion. You can configure the character set used by setting the *BASE36_CHARS environment variable to a string containing the desired characters.
export BASE36_CHARS="A32145789U0BCDEFGHIJKLMNOPQRSTVWXYZ6"
The resulting number will be the decimal representation of the number in base 36.
Error Handling
If the input to either conversion method is invalid, an ArgumentException will be thrown with an appropriate error message. The message will also be printed to the console.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net7.0
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
4.0.3 | 767 | 6/21/2024 |
4.0.2 | 129 | 6/20/2024 |
4.0.1 | 130 | 6/19/2024 |
4.0.0 | 135 | 6/18/2024 |
3.0.6 | 560 | 5/8/2024 |
3.0.5 | 163 | 5/6/2024 |
3.0.4 | 139 | 4/25/2024 |
3.0.3 | 525 | 3/20/2024 |
3.0.1 | 181 | 3/13/2024 |
3.0.0 | 132 | 3/13/2024 |
2.0.2 | 499 | 12/2/2023 |
2.0.1 | 141 | 11/29/2023 |
1.0.18 | 235 | 11/8/2023 |
1.0.17 | 130 | 11/8/2023 |
1.0.16 | 269 | 11/7/2023 |
1.0.15 | 113 | 11/6/2023 |
1.0.14 | 117 | 11/6/2023 |
1.0.12 | 330 | 10/23/2023 |
1.0.11 | 220 | 7/19/2023 |
1.0.10 | 170 | 7/18/2023 |
1.0.9 | 151 | 7/18/2023 |
1.0.8 | 157 | 7/17/2023 |
1.0.7 | 194 | 6/7/2023 |
1.0.6 | 168 | 6/7/2023 |
1.0.5 | 173 | 6/6/2023 |
1.0.4 | 155 | 6/6/2023 |
1.0.1 | 173 | 5/30/2023 |
1.0.0 | 230 | 4/13/2023 |