UnicodeIdna Class

Converts internationalized domain names with Unicode IDNA Compatibility Processing (Unicode Technical Standard #46).

public static class UnicodeIdna

Remarks

The conversion does not depend on the runtime or on ICU, unlike IdnMapping: the mapping table and the normalization are the ones of UnicodeProperties.UnicodeVersion, so the results are the same on every platform and in globalization-invariant mode.

The methods never throw for an invalid domain name: they report it.

See also

Methods

NameDescription
ToUnicode(string, UnicodeIdnaOptions?, bool)Converts a domain name to its Unicode form (ToUnicode).
ToUnicode(string, bool)Converts a domain name to its Unicode form (ToUnicode), with the default options.
TryDecodePunycode(ReadOnlySpan<char>, string?)Decodes a label encoded with Punycode (RFC 3492), without the xn-- prefix.
TryEncodePunycode(ReadOnlySpan<char>, string?)Encodes a label with Punycode (RFC 3492), without the xn-- prefix.
TryToAscii(string, UnicodeIdnaOptions?, string?)Converts a domain name to its ASCII form (ToASCII).
TryToAscii(string, string?)Converts a domain name to its ASCII form (ToASCII), with the default options.

ToUnicode overloads

ToUnicode(string, UnicodeIdnaOptions?, bool)

UnicodeIdna.cs

Converts a domain name to its Unicode form (ToUnicode).

public static string ToUnicode(string domainName, UnicodeIdnaOptions? options, out bool hasErrors)
Parameters
domainName string
The domain name, such as xn--bcher-kva.example.
options UnicodeIdnaOptions?
The options of the processing, or null for UnicodeIdnaOptions.Default. UnicodeIdnaOptions.VerifyDnsLength is not used.
hasErrors bool
true when the domain name is not valid; the result is still converted as much as possible.
Returns

string The Unicode form, such as bücher.example.

See also

ToUnicode(string, bool)

UnicodeIdna.cs

Converts a domain name to its Unicode form (ToUnicode), with the default options.

public static string ToUnicode(string domainName, out bool hasErrors)
Parameters
domainName string
The domain name, such as xn--bcher-kva.example.
hasErrors bool
true when the domain name is not valid; the result is still converted as much as possible.
Returns

string The Unicode form, such as bücher.example.

See also

TryDecodePunycode(ReadOnlySpan<char>, string?)

UnicodeIdna.cs

Decodes a label encoded with Punycode (RFC 3492), without the xn-- prefix.

public static bool TryDecodePunycode(ReadOnlySpan<char> value, out string? result)

Parameters

value ReadOnlySpan<char>
The encoded label, such as bcher-kva.
result string?
The decoded label, such as bücher, when the method returns true.

Returns

bool true when the label is valid Punycode.

See also

TryEncodePunycode(ReadOnlySpan<char>, string?)

UnicodeIdna.cs

Encodes a label with Punycode (RFC 3492), without the xn-- prefix.

public static bool TryEncodePunycode(ReadOnlySpan<char> value, out string? result)

Parameters

value ReadOnlySpan<char>
The label, such as bücher. The case of the letters is kept.
result string?
The encoded label, such as bcher-kva, when the method returns true.

Returns

bool true when the label is encoded; false when the encoding overflows, or when the label has an unpaired surrogate, which has no code point to encode.

See also

TryToAscii overloads

TryToAscii(string, UnicodeIdnaOptions?, string?)

UnicodeIdna.cs

Converts a domain name to its ASCII form (ToASCII).

public static bool TryToAscii(string domainName, UnicodeIdnaOptions? options, out string? result)
Parameters
domainName string
The domain name, such as Bücher.example.
options UnicodeIdnaOptions?
The options of the processing, or null for UnicodeIdnaOptions.Default.
result string?
The ASCII form, such as xn--bcher-kva.example, when the method returns true.
Returns

bool true when the domain name is valid.

See also

TryToAscii(string, string?)

UnicodeIdna.cs

Converts a domain name to its ASCII form (ToASCII), with the default options.

public static bool TryToAscii(string domainName, out string? result)
Parameters
domainName string
The domain name, such as Bücher.example.
result string?
The ASCII form, such as xn--bcher-kva.example, when the method returns true.
Returns

bool true when the domain name is valid.

See also