Struct Link<TLinkAddress>
Represents a link in the Links Notation with an optional identifier and nested values. Links can represent simple references, complex nested structures, or relationships between references to links.
Implements
Inherited Members
Namespace: Link.Foundation.Links.Notation
Assembly: Link.Foundation.Links.Notation.dll
Syntax
public struct Link<TLinkAddress> : IEquatable<Link<TLinkAddress>>
Type Parameters
| Name | Description |
|---|---|
| TLinkAddress | The type used for link addresses/identifiers. This can be any type that uniquely identifies a link, such as string, int, or Guid. |
Constructors
| Edit this page View SourceLink(params Link<TLinkAddress>[])
Initializes a new anonymous link with the specified array of values.
Declaration
public Link(params Link<TLinkAddress>[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| Link<TLinkAddress>[] | values | The nested link values as a parameter array. |
Link(IList<Link<TLinkAddress>>)
Initializes a new anonymous link with the specified values.
Declaration
public Link(IList<Link<TLinkAddress>> values)
Parameters
| Type | Name | Description |
|---|---|---|
| IList<Link<TLinkAddress>> | values | The nested link values. |
Link(TLinkAddress)
Initializes a new simple reference link with the specified identifier.
Declaration
public Link(TLinkAddress id)
Parameters
| Type | Name | Description |
|---|---|---|
| TLinkAddress | id | The link identifier or address. |
Link(TLinkAddress?, IList<Link<TLinkAddress>>?)
Initializes a new link with the specified identifier and values.
Declaration
public Link(TLinkAddress? id, IList<Link<TLinkAddress>>? values)
Parameters
| Type | Name | Description |
|---|---|---|
| TLinkAddress | id | The link identifier or address. |
| IList<Link<TLinkAddress>> | values | The nested link values. |
Fields
| Edit this page View SourceId
Gets the identifier or address of this link. Can be null for anonymous links.
Declaration
public readonly TLinkAddress? Id
Field Value
| Type | Description |
|---|---|
| TLinkAddress |
Values
Gets the collection of nested link values. Can be null or empty for simple reference links.
Declaration
public readonly IList<Link<TLinkAddress>>? Values
Field Value
| Type | Description |
|---|---|
| IList<Link<TLinkAddress>> |
Methods
| Edit this page View SourceCombine(Link<TLinkAddress>)
Combines this link with another link to create a new link containing both as values.
Declaration
public Link<TLinkAddress> Combine(Link<TLinkAddress> other)
Parameters
| Type | Name | Description |
|---|---|---|
| Link<TLinkAddress> | other | The other link to combine with. |
Returns
| Type | Description |
|---|---|
| Link<TLinkAddress> | A new link containing both links as values. |
Equals(Link<TLinkAddress>)
Indicates whether the current link is equal to another link. Two anonymous links (both with null Ids) are considered equal if their values are equal.
Declaration
public bool Equals(Link<TLinkAddress> other)
Parameters
| Type | Name | Description |
|---|---|---|
| Link<TLinkAddress> | other | The link to compare with this link. |
Returns
| Type | Description |
|---|---|
| bool | True if the current link is equal to the other parameter; otherwise, false. |
Equals(object?)
Determines whether the specified object is equal to this link.
Declaration
public override bool Equals(object? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with this link. |
Returns
| Type | Description |
|---|---|
| bool | True if the specified object is equal to this link; otherwise, false. |
Overrides
| Edit this page View SourceEscapeReference(string?)
Escapes a reference string for safe use in Links Notation format by adding quotes if necessary.
Declaration
public static string EscapeReference(string? reference)
Parameters
| Type | Name | Description |
|---|---|---|
| string | reference | The reference string to escape. |
Returns
| Type | Description |
|---|---|
| string | The escaped reference string with appropriate quoting. |
GetHashCode()
Returns the hash code for this link.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code for this link. |
Overrides
| Edit this page View SourceGetValueString(Link<TLinkAddress>)
Gets the string representation of a link value, choosing the appropriate format.
Declaration
public static string GetValueString(Link<TLinkAddress> value)
Parameters
| Type | Name | Description |
|---|---|---|
| Link<TLinkAddress> | value | The link value to convert to string. |
Returns
| Type | Description |
|---|---|
| string | The string representation of the link value. |
GetValuesString()
Gets the string representation of the link's values.
Declaration
public string GetValuesString()
Returns
| Type | Description |
|---|---|
| string | A space-separated string of the values, or empty string if no values exist. |
Simplify()
Simplifies the link structure by unwrapping single-value containers and recursively simplifying nested values.
Declaration
public Link<TLinkAddress> Simplify()
Returns
| Type | Description |
|---|---|
| Link<TLinkAddress> | A simplified version of this link. |
ToLinkOrIdString()
Converts the link to its string representation, choosing between simple reference format or full link format.
Declaration
public string ToLinkOrIdString()
Returns
| Type | Description |
|---|---|
| string | A string representation optimized for the link's content. |
ToString()
Returns the string representation of this link in Links Notation format.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string representation of the link with proper escaping and formatting. |
Overrides
Operators
| Edit this page View Sourceoperator ==(Link<TLinkAddress>, Link<TLinkAddress>)
Determines whether two link instances are equal.
Declaration
public static bool operator ==(Link<TLinkAddress> left, Link<TLinkAddress> right)
Parameters
| Type | Name | Description |
|---|---|---|
| Link<TLinkAddress> | left | The first link to compare. |
| Link<TLinkAddress> | right | The second link to compare. |
Returns
| Type | Description |
|---|---|
| bool | True if the links are equal; otherwise, false. |
implicit operator Link<TLinkAddress>((Link<TLinkAddress> source, Link<TLinkAddress> linker, Link<TLinkAddress> target))
Implicitly converts a source-linker-target triplet to an anonymous link.
Declaration
public static implicit operator Link<TLinkAddress>((Link<TLinkAddress> source, Link<TLinkAddress> linker, Link<TLinkAddress> target) value)
Parameters
| Type | Name | Description |
|---|---|---|
| (Link<TLinkAddress> source, Link<TLinkAddress> linker, Link<TLinkAddress> target) | value | The tuple containing source, linker, and target links. |
Returns
| Type | Description |
|---|---|
| Link<TLinkAddress> |
implicit operator Link<TLinkAddress>((Link<TLinkAddress> source, Link<TLinkAddress> target))
Implicitly converts a source-target pair to an anonymous link.
Declaration
public static implicit operator Link<TLinkAddress>((Link<TLinkAddress> source, Link<TLinkAddress> target) value)
Parameters
| Type | Name | Description |
|---|---|---|
| (Link<TLinkAddress> source, Link<TLinkAddress> target) | value | The tuple containing source and target links. |
Returns
| Type | Description |
|---|---|
| Link<TLinkAddress> |
implicit operator Link<TLinkAddress>((id<TLinkAddress> id, Link<TLinkAddress> source, Link<TLinkAddress> linker, Link<TLinkAddress> target))
Implicitly converts a tuple of identifier, source, linker, and target to a link.
Declaration
public static implicit operator Link<TLinkAddress>((id<TLinkAddress> id, Link<TLinkAddress> source, Link<TLinkAddress> linker, Link<TLinkAddress> target) value)
Parameters
| Type | Name | Description |
|---|---|---|
| (id<TLinkAddress> id, Link<TLinkAddress> source, Link<TLinkAddress> linker, Link<TLinkAddress> target) | value | The tuple containing id, source, linker, and target. |
Returns
| Type | Description |
|---|---|
| Link<TLinkAddress> |
implicit operator Link<TLinkAddress>((id<TLinkAddress> id, Link<TLinkAddress> source, Link<TLinkAddress> target))
Implicitly converts a tuple of identifier, source, and target to a link.
Declaration
public static implicit operator Link<TLinkAddress>((id<TLinkAddress> id, Link<TLinkAddress> source, Link<TLinkAddress> target) value)
Parameters
| Type | Name | Description |
|---|---|---|
| (id<TLinkAddress> id, Link<TLinkAddress> source, Link<TLinkAddress> target) | value | The tuple containing id, source and target. |
Returns
| Type | Description |
|---|---|
| Link<TLinkAddress> |
implicit operator Link<TLinkAddress>((TLinkAddress, IList<Link<TLinkAddress>>))
Implicitly converts a tuple of identifier and values to a link.
Declaration
public static implicit operator Link<TLinkAddress>((TLinkAddress, IList<Link<TLinkAddress>>) value)
Parameters
| Type | Name | Description |
|---|---|---|
| (TLinkAddress, IList<Link<TLinkAddress>>) | value | The tuple containing identifier and values. |
Returns
| Type | Description |
|---|---|
| Link<TLinkAddress> |
implicit operator Link<TLinkAddress>(TLinkAddress)
Implicitly converts a value to a simple reference link.
Declaration
public static implicit operator Link<TLinkAddress>(TLinkAddress value)
Parameters
| Type | Name | Description |
|---|---|---|
| TLinkAddress | value | The value to convert. |
Returns
| Type | Description |
|---|---|
| Link<TLinkAddress> |
operator !=(Link<TLinkAddress>, Link<TLinkAddress>)
Determines whether two link instances are not equal.
Declaration
public static bool operator !=(Link<TLinkAddress> left, Link<TLinkAddress> right)
Parameters
| Type | Name | Description |
|---|---|---|
| Link<TLinkAddress> | left | The first link to compare. |
| Link<TLinkAddress> | right | The second link to compare. |
Returns
| Type | Description |
|---|---|
| bool | True if the links are not equal; otherwise, false. |