Table of Contents

Class MessageExtensions

Namespace
Savvyio.Messaging
Assembly
Savvyio.Messaging.dll

Extension methods for the IMessage<T> interface.

public static class MessageExtensions
Inheritance
MessageExtensions

Examples

This example shows how to clone a message envelope before adding transport-specific state to the copy.

using System;
using Savvyio;
using Savvyio.Messaging;

namespace ExampleApp;

public sealed class MessageExtensionsExample
{
    public IMessage<CreateOrderCommand> Clone()
    {
        var original = new Message<CreateOrderCommand>("msg-42", new Uri("urn:orders"), "orders.created", new CreateOrderCommand("ORD-42"));
        return original.Clone();
    }
}

public sealed record CreateOrderCommand(string OrderId) : Request;

Methods

Clone<T>(IMessage<T>, Func<IMessage<T>>)

Clones the specified message using either the specified copier or the default implementation that return a new instance of Message<T>.

public static IMessage<T> Clone<T>(this IMessage<T> message, Func<IMessage<T>> copier = null) where T : IRequest

Parameters

message IMessage<T>

The IMessage<T> to clone.

copier Func<IMessage<T>>

The function delegate that is used to clone the specified message. Default is null.

Returns

IMessage<T>

An implementation of IMessage<T> that is an otherwise clone of the specified message.

Type Parameters

T

The type of the payload constraint to the IRequest interface.

Exceptions

ArgumentNullException

message cannot be null.