Table of Contents

Struct Recipient

Namespace
Signal.Domain.ValueObjects
Assembly
Signal.Domain.dll

Anything a message can be addressed to: exactly one of a PhoneNumber, an AccountId (ACI/UUID), a Username or a GroupId.

public struct Recipient : IUnion
Implements
Inherited Members

Remarks

A C# union: every case type converts implicitly (Recipient r = phoneNumber;), and pattern matching applies to the contained value, with exhaustiveness checking:

var label = recipient switch
{
    PhoneNumber n => $"phone {n}",
    AccountId id => $"account {id}",
    Username u => $"@{u}",
    GroupId g => $"group {g}",
};

Address is the string sent to the REST API.

Properties

Address

The identifier in the form expected by the REST API.

public string Address { get; }

Property Value

string

Exceptions

InvalidOperationException

The recipient is default (holds no value).

IsGroup

Whether this recipient is a group.

public bool IsGroup { get; }

Property Value

bool

Methods

Parse(string)

Detects the recipient kind from its textual form. Tried in order: group id (group.…), phone number, UUID; anything else is treated as a username.

public static Recipient Parse(string value)

Parameters

value string

The text to interpret.

Returns

Recipient

The recipient.

Exceptions

InvalidRecipientException

value is empty or an invalid username.

ToString()

Returns Address.

public override string ToString()

Returns

string

The API representation of this recipient, or an empty string for default.

TryParse(string?, out Recipient)

Tries to detect the recipient kind from its textual form (see Parse(string)).

public static bool TryParse(string? value, out Recipient recipient)

Parameters

value string

The text to interpret.

recipient Recipient

The recipient when the method returns true.

Returns

bool

true if value is a valid recipient.