Class MessageHeaderEnumerableExtensions
Add some helper methods to the IEnumerable<T> of MessageHeader.
Inherited Members
Namespace: Silverback.Messaging.Messages
Assembly: Silverback.Integration.dll
Syntax
public static class MessageHeaderEnumerableExtensions
Methods
| Improve this doc View sourceContains(IEnumerable<MessageHeader>, string)
Returns a boolean value indicating whether an header with the specified name has already been added to the collection.
Declaration
public static bool Contains(this IEnumerable<MessageHeader> headers, string name)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<MessageHeader> | headers | The enumerable containing the headers to be searched. |
| string | name | The name to be checked. |
Returns
| Type | Description |
|---|---|
| bool | A boolean value indicating whether the name was found in the existing headers. |
GetValue(IEnumerable<MessageHeader>, string, bool)
Returns the value of the header with the specified name.
It will return null if no header with that name is found in the collection.
Declaration
public static string? GetValue(this IEnumerable<MessageHeader> headers, string name, bool throwIfNotFound = false)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<MessageHeader> | headers | The enumerable containing the headers to be searched. |
| string | name | The name of the header to be retrieved. |
| bool | throwIfNotFound | A boolean value specifying whether an exception must be thrown if the header with the specified name is not found (or the value cannot be converted to the specified type). |
Returns
| Type | Description |
|---|---|
| string | The header value converted to the target type, or |
GetValue(IEnumerable<MessageHeader>, string, Type, bool)
Returns the value of the header with the specified name, casting it to the specified type.
By default it will return null if no header with that name is found in the collection but
this behavior can be changed
setting the throwIfNotFound parameter to true.
Declaration
public static object? GetValue(this IEnumerable<MessageHeader> headers, string name, Type targetType, bool throwIfNotFound = false)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<MessageHeader> | headers | The enumerable containing the headers to be searched. |
| string | name | The name of the header to be retrieved. |
| Type | targetType | The type to convert the header value to. |
| bool | throwIfNotFound | A boolean value specifying whether an exception must be thrown if the header with the specified name is not found (or the value cannot be converted to the specified type). |
Returns
| Type | Description |
|---|---|
| object | The header value converted to the target type, or |
GetValueOrDefault(IEnumerable<MessageHeader>, string, Type)
Returns the value of the header with the specified name, casting it to the specified type.
It will return the default value for the target type if no header with that name is found in the collection.
Declaration
public static object? GetValueOrDefault(this IEnumerable<MessageHeader> headers, string name, Type targetType)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<MessageHeader> | headers | The enumerable containing the headers to be searched. |
| string | name | The name of the header to be retrieved. |
| Type | targetType | The type to convert the header value to. |
Returns
| Type | Description |
|---|---|
| object | The header value converted to the target type, or |
GetValueOrDefault<T>(IEnumerable<MessageHeader>, string)
Returns the value of the header with the specified name, casting it to the specified type
T.
It will return the default value for the type T if no header with that
name is found in the collection.
Declaration
public static T GetValueOrDefault<T>(this IEnumerable<MessageHeader> headers, string name) where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<MessageHeader> | headers | The enumerable containing the headers to be searched. |
| string | name | The name of the header to be retrieved. |
Returns
| Type | Description |
|---|---|
| T | The header value converted to the target type, or |
Type Parameters
| Name | Description |
|---|---|
| T | The type to convert the header value to. |
GetValue<T>(IEnumerable<MessageHeader>, string, bool)
Returns the value of the header with the specified name, casting it to the specified type
T.
It will return null if no header with that name is found in the collection.
Declaration
public static T? GetValue<T>(this IEnumerable<MessageHeader> headers, string name, bool throwIfNotFound = false) where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<MessageHeader> | headers | The enumerable containing the headers to be searched. |
| string | name | The name of the header to be retrieved. |
| bool | throwIfNotFound | A boolean value specifying whether an exception must be thrown if the header with the specified name is not found (or the value cannot be converted to the specified type). |
Returns
| Type | Description |
|---|---|
| T? | The header value converted to the target type, or |
Type Parameters
| Name | Description |
|---|---|
| T | The type to convert the header value to. |