UnicodeIdna Class
Converts internationalized domain names with Unicode IDNA Compatibility Processing (Unicode Technical Standard #46).
public static class UnicodeIdnaRemarks
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
| Name | Description |
|---|---|
| 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.csConverts a domain name to its Unicode form (ToUnicode).
public static string ToUnicode(string domainName, UnicodeIdnaOptions? options, out bool hasErrors)Parameters
domainNamestring- The domain name, such as
xn--bcher-kva.example. optionsUnicodeIdnaOptions?- The options of the processing, or
nullforUnicodeIdnaOptions.Default.UnicodeIdnaOptions.VerifyDnsLengthis not used. hasErrorsbooltruewhen 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.csConverts a domain name to its Unicode form (ToUnicode), with the default options.
TryDecodePunycode(ReadOnlySpan<char>, string?)
UnicodeIdna.csDecodes a label encoded with Punycode (RFC 3492), without the xn-- prefix.
public static bool TryDecodePunycode(ReadOnlySpan<char> value, out string? result)Parameters
valueReadOnlySpan<char>- The encoded label, such as
bcher-kva. resultstring?- The decoded label, such as
bücher, when the method returnstrue.
Returns
bool true when the label is valid Punycode.
See also
TryEncodePunycode(ReadOnlySpan<char>, string?)
UnicodeIdna.csEncodes a label with Punycode (RFC 3492), without the xn-- prefix.
public static bool TryEncodePunycode(ReadOnlySpan<char> value, out string? result)Parameters
valueReadOnlySpan<char>- The label, such as
bücher. The case of the letters is kept. resultstring?- The encoded label, such as
bcher-kva, when the method returnstrue.
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.csConverts a domain name to its ASCII form (ToASCII).
public static bool TryToAscii(string domainName, UnicodeIdnaOptions? options, out string? result)Parameters
domainNamestring- The domain name, such as
Bücher.example. optionsUnicodeIdnaOptions?- The options of the processing, or
nullforUnicodeIdnaOptions.Default. resultstring?- The ASCII form, such as
xn--bcher-kva.example, when the method returnstrue.
Returns
bool true when the domain name is valid.