PandaTech.BaseConverter 3.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package PandaTech.BaseConverter --version 3.0.6                
NuGet\Install-Package PandaTech.BaseConverter -Version 3.0.6                
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="3.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PandaTech.BaseConverter --version 3.0.6                
#r "nuget: PandaTech.BaseConverter, 3.0.6"                
#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=3.0.6

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

1. Pandatech.BaseConverter

The Pandatech.BaseConverter library offers robust and flexible base conversion functionalities, enabling seamless transformations between base 10 and base 36 numeral systems. Designed for simplicity and efficiency, it's an essential tool for applications requiring numeral system conversions, particularly useful in scenarios like generating concise, URL-friendly unique identifiers from numeric values. Available as a convenient NuGet package, it integrates effortlessly into your .NET projects.

1.1. Features

  • Bi-directional Conversion: Supports converting numbers from base 10 to base 36 and vice versa.
  • Custom Character Set Configuration: Allows customization of the character set used for base 36 encoding, enabling unique identifier generation tailored to specific requirements.
  • Integration with Data Transfer Objects (DTOs): Facilitates the use of base 36 encoded strings in DTOs, enhancing API usability and readability.
  • Swagger Integration: Ensures seamless integration with Swagger for API documentation and testing, with support for custom parameter converters.
  • Robust Validation: Offers built-in validation for base 36 inputs, ensuring data integrity and error resilience.
  • Exception Handling: Provides clear and informative error messages for invalid inputs, aiding in troubleshooting and debugging.

1.2. Installation

To include Pandatech.BaseConverter in your project, install it as a NuGet package:

Install-Package Pandatech.BaseConverter

1.3. Basic Usage

Converting from Base 10 to Base 36 (2 overloads for nullable and non-nullable output)

long number = 12345;
string base36Number = BaseConverter.PandaBaseConverter.Base10ToBase36(number);
// Output: base36Number = "9ix"

Converting from Base 36 to Base 10 (nullable input and output)

string base36Number = "9ix";
long? number = BaseConverter.PandaBaseConverter.Base36ToBase10(base36Number);
// Output: number = 12345

Converting from Base 36 to Base 10 (non-nullable input and output)

string base36Number = "9ix";
long number = BaseConverter.PandaBaseConverter.Base36ToBase10NotNull(base36Number, false);
// Output: number = 12345

1.4. Advanced Usage

1.4.1. Customizing Base 36 Character Set

You can customize the character set used for base 36 encoding to suit your application's needs, for not exposing actual order:

var builder = WebApplication.CreateBuilder(args);
var customCharset = "0123456789abcdefghijklmnopqrstuvwxyz";
builder.Services.ConfigureBaseConverter(customCharset);

1.4.2. Integration with DTOs

Decorate DTO properties with [PandaPropertyBaseConverter] to automatically handle base 36 encoding/decoding:

public class MyDto
{
    [PandaPropertyBaseConverter]
    public long Id { get; set; }
}

1.4.3. Controller Parameter Binding

Use [PandaParameterBaseConverter] to automatically resolve base 36 encoded parameters in controller actions:

[HttpGet("{id}")]
public async Task<ActionResult<MyDto>> Get([PandaParameterBaseConverter] long id)
{
    // Your logic here
}

1.4.4. Validation

Validate base 36 inputs using the ValidateBase36Chars extension method:

string base36Number = "9ix";
bool isValid = base36Number.ValidateBase36Chars();
// Output: isValid = true

1.4.5. Swagger Integration

builder.Services.AddSwaggerGen(
    options =>
    {
        options.ParameterFilter<PandaParameterBaseConverterAttribute>();
        options.SchemaFilter<PandaPropertyBaseConverterSwaggerFilter>();
    }
);

1.4.6. Error Handling

The library employs ArgumentException to signal invalid inputs, equipped with descriptive messages to facilitate debugging:

try
{
    var result = BaseConverter.PandaBaseConverter.Base36ToBase10("invalid-input");
}
catch (ArgumentException ex)
{
    Console.WriteLine(ex.Message);
    // Handle the exception as needed
}

1.5. Contributing

Contributions are welcome! If you have suggestions for improvements or encounter any issues, please feel free to open an issue or submit a pull request.

1.6. License

This project is licensed under the MIT License. Feel free to use, modify, and distribute it as per the license terms.

Thank you for choosing Pandatech.BaseConverter for your base conversion needs!

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)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

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

Package Downloads
PandaTech.IEnumerableFilters

This NuGet helps with filtering tables.

Pandatech.EFCoreQueryMagic

Unlock the full potential of your Entity Framework Core applications with Pandatech.EFCoreQueryMagic. This innovative package empowers developers to seamlessly create dynamic, complex queries and filters for SQL tables without diving deep into the intricacies of LINQ or manual query construction. Designed to enhance productivity and maintainability, EFCoreQueryMagic automates the translation of front-end filter requests into optimized, ready-to-execute EF Core queries. Embrace the magic of streamlined data retrieval and manipulation, and elevate your applications to new heights of efficiency and performance.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.3 481 6/21/2024
4.0.2 117 6/20/2024
4.0.1 118 6/19/2024
4.0.0 123 6/18/2024
3.0.6 430 5/8/2024
3.0.5 153 5/6/2024
3.0.4 129 4/25/2024
3.0.3 507 3/20/2024
3.0.1 173 3/13/2024
3.0.0 120 3/13/2024
2.0.2 491 12/2/2023
2.0.1 133 11/29/2023
1.0.18 220 11/8/2023
1.0.17 118 11/8/2023
1.0.16 261 11/7/2023
1.0.15 103 11/6/2023
1.0.14 109 11/6/2023
1.0.12 322 10/23/2023
1.0.11 206 7/19/2023
1.0.10 162 7/18/2023
1.0.9 143 7/18/2023
1.0.8 147 7/17/2023
1.0.7 186 6/7/2023
1.0.6 160 6/7/2023
1.0.5 165 6/6/2023
1.0.4 145 6/6/2023
1.0.1 165 5/30/2023
1.0.0 220 4/13/2023

Property Attribute will work on fields as well