ReferenceGenerator 2.0.0

dotnet add package ReferenceGenerator --version 2.0.0
                    
NuGet\Install-Package ReferenceGenerator -Version 2.0.0
                    
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="ReferenceGenerator" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ReferenceGenerator" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ReferenceGenerator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ReferenceGenerator --version 2.0.0
                    
#r "nuget: ReferenceGenerator, 2.0.0"
                    
#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.
#:package ReferenceGenerator@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ReferenceGenerator&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ReferenceGenerator&version=2.0.0
                    
Install as a Cake Tool

ReferenceGenerator

NuGet NuGet Downloads License: MIT

A lightweight, flexible C# library for generating unique reference numbers in various formats. Perfect for creating order numbers, transaction IDs, document references, payment references, and more.

Features

  • Multiple formats: Numeric, alphabetic, alphanumeric, and GUID generation
  • Check digit support: Luhn, Mod97 (IBAN), Verhoeff, and Damm algorithms
  • Template-based generation: Powerful template syntax for custom formats
  • Human-friendly mode: Excludes ambiguous characters (0/O, 1/I/l)
  • Cryptographically secure: Option for security-critical applications
  • Sequence support: Auto-incrementing references with padding
  • Cross-platform: Supports .NET Standard 2.0, .NET 6.0, and .NET 8.0
  • DI-friendly: Includes interface for dependency injection
  • Zero dependencies: No external runtime dependencies

Installation

dotnet add package ReferenceGenerator

Or via Package Manager Console:

Install-Package ReferenceGenerator

Quick Start

using ReferenceGenerator;

// Generate a 10-digit numeric reference
string numericRef = ReferenceNumberGenerator.GenerateNumeric(10);
// Example: "1234567890"

// Generate with prefix
string orderRef = ReferenceNumberGenerator.GenerateNumeric(6, "ORD-");
// Example: "ORD-123456"

// Generate alphanumeric
string alphanumericRef = ReferenceNumberGenerator.GenerateAlphanumeric(12);
// Example: "A1B2C3D4E5F6"

// Generate cryptographically secure reference
string secureRef = ReferenceNumberGenerator.GenerateSecure(16);
// Example: "X7Y9Z2W4P5Q8R1S3"

Check Digit Support

Generate references with built-in check digit validation - perfect for payment references, invoice numbers, and any system requiring error detection.

Supported Algorithms

Algorithm Use Case Check Digits
Luhn (Mod 10) Credit cards, IMEI numbers 1 digit
Mod 97 IBAN validation (ISO 7064) 2 digits
Verhoeff High-security applications 1 digit
Damm Error detection 1 digit

Usage

using ReferenceGenerator;
using ReferenceGenerator.CheckDigit;

// Generate with Luhn check digit
string paymentRef = ReferenceNumberGenerator.GenerateNumericWithCheckDigit(9, CheckDigitAlgorithm.Luhn);
// Example: "1234567893" (where 3 is the check digit)

// Validate a reference
bool isValid = ReferenceNumberGenerator.ValidateLuhn("1234567893"); // true

// Generate with different algorithms
string verhoeffRef = ReferenceNumberGenerator.GenerateNumericWithCheckDigit(8, CheckDigitAlgorithm.Verhoeff);
string dammRef = ReferenceNumberGenerator.GenerateNumericWithCheckDigit(8, CheckDigitAlgorithm.Damm);

// Direct check digit calculation
char checkDigit = CheckDigitCalculator.CalculateLuhn("123456789"); // '7'
string mod97Digits = CheckDigitCalculator.CalculateMod97("ABCD1234"); // "XX"

Template-Based Generation

Create complex reference formats using a powerful template syntax.

Template Placeholders

Placeholder Description Example
{NUMERIC:n} n random digits {NUMERIC:6} → "482917"
{ALPHA:n} n uppercase letters {ALPHA:4} → "XKWM"
{ALPHANUMERIC:n} n letters/digits {ALPHANUMERIC:8} → "A3B7K2M9"
{DATE:format} Formatted date/time {DATE:yyyyMMdd} → "20250123"
{GUID} Standard GUID {GUID} → "550e8400-e29b-..."
{GUID:N} GUID without dashes {GUID:N} → "550e8400e29b..."
{SEQ:n} Padded sequence {SEQ:5} → "00001"
{VAR:name} Custom variable {VAR:region} → (your value)
{CHECK:algo} Check digit {CHECK:Luhn} → "3"
{SECURE:n} Crypto-secure random {SECURE:10} → "X7Y9Z2W4P5"

Template Examples

using ReferenceGenerator;
using ReferenceGenerator.Templates;

// Simple template
string orderRef = ReferenceNumberGenerator.FromTemplate(
    "ORD-{DATE:yyyyMMdd}-{NUMERIC:4}");
// Example: "ORD-20250123-4829"

// With variables
string invoiceRef = ReferenceNumberGenerator.FromTemplate(
    "{VAR:prefix}-{DATE:yyMM}-{NUMERIC:6}",
    new { prefix = "INV" });
// Example: "INV-2501-482917"

// With check digit
string paymentRef = ReferenceNumberGenerator.FromTemplate(
    "PAY{NUMERIC:9}{CHECK:Luhn}");
// Example: "PAY1234567893" (Luhn-validated)

// With sequence numbers (reusable template)
var template = ReferenceNumberGenerator.CreateTemplate("TXN-{SEQ:6}", startSequence: 1000);
template.Generate(); // "TXN-001000"
template.Generate(); // "TXN-001001"
template.Generate(); // "TXN-001002"

// Complex multi-part reference
string complexRef = ReferenceNumberGenerator.FromTemplate(
    "{VAR:country}{DATE:yyMMdd}{ALPHA:2}{NUMERIC:4}{CHECK:Damm}",
    new { country = "NG" });
// Example: "NG250123XK48293"

Batch Generation

var template = new ReferenceTemplate("{ALPHANUMERIC:12}");
string[] batchRefs = template.GenerateMany(100);
// Generates 100 unique references

Human-Friendly References

Generate references that avoid ambiguous characters (0/O, 1/I/l) for better readability when users need to type or read references.

// Excludes 0, O, 1, I, l
string friendlyRef = ReferenceNumberGenerator.GenerateHumanFriendly(8);
// Example: "X7K2M9P4" (never contains ambiguous characters)

Dependency Injection

The library includes an IReferenceGenerator interface for easy DI integration:

// Register in DI container
services.AddSingleton<IReferenceGenerator, ReferenceNumberGenerator>();

// Inject and use
public class OrderService
{
    private readonly IReferenceGenerator _refGen;
    
    public OrderService(IReferenceGenerator refGen)
    {
        _refGen = refGen;
    }
    
    public string CreateOrder()
    {
        return _refGen.GenerateNumericWithCheckDigit(9, CheckDigitAlgorithm.Luhn, "ORD-");
    }
}

API Reference

Static Methods

// Basic generation
ReferenceNumberGenerator.GenerateNumeric(int length, string? prefix = null)
ReferenceNumberGenerator.GenerateAlphabetic(int length, string? prefix = null)
ReferenceNumberGenerator.GenerateAlphanumeric(int length, string? prefix = null)
ReferenceNumberGenerator.GenerateGuid(string? prefix = null)
ReferenceNumberGenerator.GenerateSecure(int length, string? prefix = null)
ReferenceNumberGenerator.GenerateHumanFriendly(int length, string? prefix = null)

// With check digit
ReferenceNumberGenerator.GenerateNumericWithCheckDigit(int length, CheckDigitAlgorithm algo, string? prefix = null)

// Validation
ReferenceNumberGenerator.ValidateLuhn(string reference)
ReferenceNumberGenerator.ValidateMod97(string reference)
ReferenceNumberGenerator.ValidateVerhoeff(string reference)
ReferenceNumberGenerator.ValidateDamm(string reference)
ReferenceNumberGenerator.Validate(string reference, CheckDigitAlgorithm algorithm)

// Template-based
ReferenceNumberGenerator.FromTemplate(string template, object? variables = null)
ReferenceNumberGenerator.CreateTemplate(string template, long startSequence = 1)

CheckDigitCalculator

// Calculate check digits
CheckDigitCalculator.CalculateLuhn(string number)      // Returns char
CheckDigitCalculator.CalculateMod97(string reference)  // Returns string (2 chars)
CheckDigitCalculator.CalculateVerhoeff(string number)  // Returns char
CheckDigitCalculator.CalculateDamm(string number)      // Returns char

// Generic methods
CheckDigitCalculator.Calculate(string input, CheckDigitAlgorithm algorithm)
CheckDigitCalculator.Validate(string input, CheckDigitAlgorithm algorithm)
CheckDigitCalculator.AppendCheckDigit(string input, CheckDigitAlgorithm algorithm)

Use Cases

  • E-commerce: Order numbers, invoice references
  • Fintech: Payment references, transaction IDs
  • Healthcare: Patient IDs, prescription numbers
  • Logistics: Tracking numbers, shipment references
  • Government: Document numbers, application IDs
  • Any system requiring unique, validated identifiers

Contributing

Contributions are welcome! Please read our contributing guidelines before submitting pull requests.

Development Setup

  1. Clone the repository
  2. Open ReferenceGenerator.sln in Visual Studio or your preferred IDE
  3. Run tests: dotnet test

Running Tests

dotnet test

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any issues or have questions:

  1. Check existing issues
  2. Create a new issue if your problem hasn't been reported
  3. Provide as much detail as possible when reporting issues

Author

Okwuchi Uzoigwe - GitHub

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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 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.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.0 48 1/23/2026
1.0.0 195 2/14/2025