PandaTech.BaseConverter 2.0.2

dotnet add package PandaTech.BaseConverter --version 2.0.2
NuGet\Install-Package PandaTech.BaseConverter -Version 2.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PandaTech.BaseConverter" Version="2.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PandaTech.BaseConverter --version 2.0.2
#r "nuget: PandaTech.BaseConverter, 2.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PandaTech.BaseConverter as a Cake Addin
#addin nuget:?package=PandaTech.BaseConverter&version=2.0.2

// Install PandaTech.BaseConverter as a Cake Tool
#tool nuget:?package=PandaTech.BaseConverter&version=2.0.2

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([PandaParameterBaseConverter] 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 doing following in program.cs.

var builder = WebApplication.CreateBuilder(args);

var base36RandomCharset = "1adfgbhjklmnepqrstvwxyz23456789";

builder.ConfigureBaseConverter(base36RandomCharset);

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.

Prgram.cs

to use PandaParameterBaseConverter in swagger, add the following code to Program.cs


builder.Services.AddSwaggerGen(
    options => 
        options.ParameterFilter<PandaParameterBaseConverter>()
    );
    
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on PandaTech.BaseConverter:

Package Downloads
PandaTech.IEnumerableFilters

This NuGet helps with filtering tables.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.2 301 12/2/2023
2.0.1 93 11/29/2023
1.0.18 139 11/8/2023
1.0.17 72 11/8/2023
1.0.16 158 11/7/2023
1.0.15 67 11/6/2023
1.0.14 66 11/6/2023
1.0.12 210 10/23/2023
1.0.11 168 7/19/2023
1.0.10 120 7/18/2023
1.0.9 110 7/18/2023
1.0.8 110 7/17/2023
1.0.7 150 6/7/2023
1.0.6 114 6/7/2023
1.0.5 126 6/6/2023
1.0.4 110 6/6/2023
1.0.1 135 5/30/2023
1.0.0 182 4/13/2023

New configuration option