Class MessageHeaders
- Namespace
- PatternKit.Messaging
- Assembly
- PatternKit.Core.dll
Immutable message metadata for in-process messaging and enterprise integration patterns.
public sealed class MessageHeaders : IReadOnlyDictionary<string, object?>, IReadOnlyCollection<KeyValuePair<string, object?>>, IEnumerable<KeyValuePair<string, object?>>, IEnumerable
- Inheritance
-
MessageHeaders
- Implements
- Inherited Members
- Extension Methods
Remarks
Header names are compared with OrdinalIgnoreCase so transport-style
names such as Correlation-Id and correlation-id resolve to the same value.
Constructors
MessageHeaders()
Creates an empty header collection.
public MessageHeaders()
MessageHeaders(IEnumerable<KeyValuePair<string, object?>>)
Creates a header collection from existing values.
public MessageHeaders(IEnumerable<KeyValuePair<string, object?>> values)
Parameters
valuesIEnumerable<KeyValuePair<string, object>>The values to copy into the immutable collection.
Exceptions
- ArgumentNullException
Thrown when
valuesis null.- ArgumentException
Thrown when a header name is null, empty, or whitespace.
Properties
CausationId
Gets the well-known causation identifier header when present.
public string? CausationId { get; }
Property Value
ContentType
Gets the well-known content type header when present.
public string? ContentType { get; }
Property Value
CorrelationId
Gets the well-known correlation identifier header when present.
public string? CorrelationId { get; }
Property Value
Count
Gets the number of elements in the collection.
public int Count { get; }
Property Value
- int
The number of elements in the collection.
Empty
An empty immutable header collection.
public static MessageHeaders Empty { get; }
Property Value
IdempotencyKey
Gets the well-known idempotency key header when present.
public string? IdempotencyKey { get; }
Property Value
this[string]
Gets the element that has the specified key in the read-only dictionary.
public object? this[string key] { get; }
Parameters
keystringThe key to locate.
Property Value
- object
The element that has the specified key in the read-only dictionary.
Exceptions
- ArgumentNullException
keyis null.- KeyNotFoundException
The property is retrieved and
keyis not found.
Keys
Gets an enumerable collection that contains the keys in the read-only dictionary.
public IEnumerable<string> Keys { get; }
Property Value
- IEnumerable<string>
An enumerable collection that contains the keys in the read-only dictionary.
MessageId
Gets the well-known message identifier header when present.
public string? MessageId { get; }
Property Value
ReplyTo
Gets the well-known reply address header when present.
public string? ReplyTo { get; }
Property Value
Timestamp
Gets the well-known timestamp header when present and parseable.
public DateTimeOffset? Timestamp { get; }
Property Value
Values
Gets an enumerable collection that contains the values in the read-only dictionary.
public IEnumerable<object?> Values { get; }
Property Value
- IEnumerable<object>
An enumerable collection that contains the values in the read-only dictionary.
Methods
ContainsKey(string)
Determines whether the read-only dictionary contains an element that has the specified key.
public bool ContainsKey(string key)
Parameters
keystringThe key to locate.
Returns
- bool
true if the read-only dictionary contains an element that has the specified key; otherwise, false.
Exceptions
- ArgumentNullException
keyis null.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<KeyValuePair<string, object?>> GetEnumerator()
Returns
- IEnumerator<KeyValuePair<string, object>>
An enumerator that can be used to iterate through the collection.
GetString(string)
Gets a string header value when present. Non-string values are converted with ToString().
public string? GetString(string name)
Parameters
namestring
Returns
TryGetDateTimeOffset(string, out DateTimeOffset)
Attempts to read a header as a DateTimeOffset or parse a string header.
public bool TryGetDateTimeOffset(string name, out DateTimeOffset value)
Parameters
namestringvalueDateTimeOffset
Returns
TryGetGuid(string, out Guid)
public bool TryGetGuid(string name, out Guid value)
Parameters
Returns
TryGetValue(string, out object?)
Gets the value that is associated with the specified key.
public bool TryGetValue(string key, out object? value)
Parameters
keystringThe key to locate.
valueobjectWhen this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the
valueparameter. This parameter is passed uninitialized.
Returns
- bool
true if the object that implements the IReadOnlyDictionary<TKey, TValue> interface contains an element that has the specified key; otherwise, false.
Exceptions
- ArgumentNullException
keyis null.
TryGet<T>(string, out T?)
Attempts to read a header as T.
public bool TryGet<T>(string name, out T? value)
Parameters
namestringvalueT
Returns
Type Parameters
T
With(string, object?)
Returns a new header collection with name set to value.
public MessageHeaders With(string name, object? value)
Parameters
Returns
WithCausationId(string)
Returns a new collection with CausationId set.
public MessageHeaders WithCausationId(string causationId)
Parameters
causationIdstring
Returns
WithContentType(string)
Returns a new collection with ContentType set.
public MessageHeaders WithContentType(string contentType)
Parameters
contentTypestring
Returns
WithCorrelationId(string)
Returns a new collection with CorrelationId set.
public MessageHeaders WithCorrelationId(string correlationId)
Parameters
correlationIdstring
Returns
WithIdempotencyKey(string)
Returns a new collection with IdempotencyKey set.
public MessageHeaders WithIdempotencyKey(string idempotencyKey)
Parameters
idempotencyKeystring
Returns
WithMessageId(string)
Returns a new collection with MessageId set.
public MessageHeaders WithMessageId(string messageId)
Parameters
messageIdstring
Returns
WithReplyTo(string)
Returns a new collection with ReplyTo set.
public MessageHeaders WithReplyTo(string replyTo)
Parameters
replyTostring
Returns
WithTimestamp(DateTimeOffset)
Returns a new collection with Timestamp set.
public MessageHeaders WithTimestamp(DateTimeOffset timestamp)
Parameters
timestampDateTimeOffset
Returns
Without(string)
Returns a new header collection without name.
public MessageHeaders Without(string name)
Parameters
namestring