Skip to content

Commit

Permalink
[Azure Service Bus] Stop copying ReadonlyMemory from original given t…
Browse files Browse the repository at this point in the history
…hat we are using an immutable and readonly memory reference (#11255)

* Stop copying ReadonlyMemory from original given that we are using an immutable and readonly memory reference

* Use object initializer
  • Loading branch information
danielmarbach authored Apr 13, 2020
1 parent 4487e70 commit 8c888b2
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions sdk/servicebus/Azure.Messaging.ServiceBus/src/ServiceBusMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,29 +267,23 @@ public override string ToString()
/// <returns></returns>
public static ServiceBusMessage CreateFrom(ServiceBusReceivedMessage message)
{
var copiedMessage = new ServiceBusMessage()
var copiedMessage = new ServiceBusMessage
{
Body = message.Body,
ContentType = message.ContentType,
CorrelationId = message.CorrelationId,
Label = message.Label,
MessageId = message.MessageId,
PartitionKey = message.PartitionKey,
Properties = new Dictionary<string, object>(message.Properties),
ReplyTo = message.ReplyTo,
ReplyToSessionId = message.ReplyToSessionId,
SessionId = message.SessionId,
ScheduledEnqueueTime = message.ScheduledEnqueueTime,
TimeToLive = message.TimeToLive,
To = message.To,
ViaPartitionKey = message.ViaPartitionKey,
ViaPartitionKey = message.ViaPartitionKey
};
var originalBody = message.Body;
if (!originalBody.IsEmpty)
{
var clonedBody = new byte[originalBody.Length];
Array.Copy(originalBody.ToArray(), clonedBody, originalBody.Length);
copiedMessage.Body = clonedBody;
}
copiedMessage.Properties = new Dictionary<string, object>(message.Properties);
return copiedMessage;
}

Expand Down

0 comments on commit 8c888b2

Please sign in to comment.