IdGenerator

Namespace: Babel.Licensing Assembly: Babel.Licensing.dll

A license identifier generator. This class cannot be inherited.

public sealed class IdGenerator

Inheritance

objectIdGenerator

Inherited Members

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Constructors

IdGenerator(string, int)

Generate a new instance of class specifying the identifier prefix and length.

public IdGenerator(string prefix, int length)

Parameters

NameDescription

prefix string

The identifier prefix.

length int

The total identifier string length.

Exceptions

NameDescription

Thrown when the prefix argument is null.

Thrown when the length argument is less or equal to zero.

IdGenerator(string)

Generate a new instance of class specifying the identifier prefix.

public IdGenerator(string prefix)

Parameters

NameDescription

prefix string

The identifier prefix.

Examples

IdGenerator builder = new IdGenerator("lic");

// licA418B7
builder.Format = IdFormat.Hex;
string idHex = builder.CreateId();

IdGenerator()

Generate a new instance of class.

public IdGenerator()

Examples

IdGenerator builder = new IdGenerator();

// id5D9E86
builder.Format = IdFormat.Hex;
string idHex = builder.CreateId();

// id153045
builder.Format = IdFormat.Decimal;
string idDec = builder.CreateId();

// id2XJC2L
builder.Format = IdFormat.Base32;
string idB32 = builder.CreateId();

Properties

Format

Gets or sets the format to use.

public IdFormat Format { get; set; }

Property Value

IdFormat

Length

Gets or sets the identifier length.

public int Length { get; set; }

Property Value

int

Exceptions

NameDescription

Thrown when one or more arguments are outside the required range.

Prefix

Gets or sets the identifier prefix.

public string Prefix { get; set; }

Property Value

string

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Methods

Create(string, int)

Creates a new identifier string with given prefix.

public static string Create(string prefix, int length)

Parameters

NameDescription

prefix string

The identifier prefix.

length int

The total identifier string length.

Returns

NameDescription

A string.

CreateId()

Creates the a new identifier string.

public string CreateId()

Returns

NameDescription

The new identifier.

Last updated