Class DomainName
A domain name consists of one or more parts, Labels, that are conventionally delimited by dots, such as "example.org".
Implements
Inherited Members
Namespace: Makaretu.Dns
Assembly: Makaretu.Dns.dll
Syntax
public class DomainName : IEquatable<DomainName>
Remarks
Equality is based on the number of and the case-insenstive contents of Labels.
Constructors
| Improve this Doc View SourceDomainName(String)
Creates a new instance of the DomainName class from the specified name.
Declaration
public DomainName(string name)
Parameters
Type | Name | Description |
---|---|---|
String | name | The dot separated labels; such as "example.org". |
Remarks
The name can contain backslash to escape a character. See RFC 4343 for the character escaping rules.
note
To use us backslash in a domain name (highly unusaual), you must use a double backslash.
DomainName(String[])
Creates a new instance of the DomainName class from the sequence of label.
Declaration
public DomainName(params string[] labels)
Parameters
Type | Name | Description |
---|---|---|
String[] | labels | The Labels. |
Remarks
The labels are not parsed; character escaping is not performed.
Fields
| Improve this Doc View SourceRoot
The root name space.
Declaration
public static DomainName Root
Field Value
Type | Description |
---|---|
DomainName | The empty string. |
Remarks
The DNS is a hierarchical naming system for computers, services, or any resource participating in the Internet. The top of that hierarchy is the root domain. The root domain does not have a formal name and its label in the DNS hierarchy is an empty string.
Properties
| Improve this Doc View SourceLabels
A sequence of labels that make up the domain name.
Declaration
public IReadOnlyList<string> Labels { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<String> | A sequece of strings. |
Remarks
The last label is the TLD (top level domain).
Methods
| Improve this Doc View SourceBelongsTo(DomainName)
Determines if this domain name is a subdomain of or equals an another domain name.
Declaration
public bool BelongsTo(DomainName domain)
Parameters
Type | Name | Description |
---|---|---|
DomainName | domain | Another domain. |
Returns
Type | Description |
---|---|
Boolean | true if this domain name is a subdomain of |
Equals(DomainName)
Declaration
public bool Equals(DomainName that)
Parameters
Type | Name | Description |
---|---|---|
DomainName | that |
Returns
Type | Description |
---|---|
Boolean |
Equals(Object)
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj |
Returns
Type | Description |
---|---|
Boolean |
Overrides
| Improve this Doc View SourceGetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 |
Overrides
| Improve this Doc View SourceIsSubdomainOf(DomainName)
Determines if this domain name is a subdomain of another domain name.
Declaration
public bool IsSubdomainOf(DomainName domain)
Parameters
Type | Name | Description |
---|---|---|
DomainName | domain | Another domain. |
Returns
Type | Description |
---|---|
Boolean | true if this domain name is a subdomain of |
Join(DomainName[])
Combine multiple domain names to form one.
Declaration
public static DomainName Join(params DomainName[] names)
Parameters
Type | Name | Description |
---|---|---|
DomainName[] | names | The domain names to join. |
Returns
Type | Description |
---|---|
DomainName | A new domain containing all the |
LabelsEqual(String, String)
Determines if the two domain name labels are equal.
Declaration
public static bool LabelsEqual(string a, string b)
Parameters
Type | Name | Description |
---|---|---|
String | a | A domain name label |
String | b | A domain name label |
Returns
Type | Description |
---|---|
Boolean | true if |
Remarks
Uses a case-insenstive algorithm, where 'A-Z' are equivalent to 'a-z'.
Parent()
Gets the parent's domain name.
Declaration
public DomainName Parent()
Returns
Type | Description |
---|---|
DomainName | The domain name of the parent or null if there is no parent; e.g. this is the root. |
ToCanonical()
Gets the canonical form of the domain name.
Declaration
public DomainName ToCanonical()
Returns
Type | Description |
---|---|
DomainName | A domain name in the canonical form. |
Remarks
All uppercase US-ASCII letters in the Labels are replaced by the corresponding lowercase US-ASCII letters.
ToString()
Returns the textual representation.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | The concatenation of the Labels separated by a dot. |
Overrides
Remarks
If a label contains a dot or backslash, then it is escaped with a backslash.
Operators
| Improve this Doc View SourceEquality(DomainName, DomainName)
Value equality.
Declaration
public static bool operator ==(DomainName a, DomainName b)
Parameters
Type | Name | Description |
---|---|---|
DomainName | a | |
DomainName | b |
Returns
Type | Description |
---|---|
Boolean |
Implicit(String to DomainName)
Implicit casting of a String to a DomainName.
Declaration
public static implicit operator DomainName(string s)
Parameters
Type | Name | Description |
---|---|---|
String | s | A possibly escaped domain name. |
Returns
Type | Description |
---|---|
DomainName | A new DomainName |
Remarks
Equivalent to
new DomainName(s)
Inequality(DomainName, DomainName)
Value inequality.
Declaration
public static bool operator !=(DomainName a, DomainName b)
Parameters
Type | Name | Description |
---|---|---|
DomainName | a | |
DomainName | b |
Returns
Type | Description |
---|---|
Boolean |