in extensions/Worker.Extensions.ServiceBus/src/ServiceBusMessageActions.cs [208:276]
private static bool TryCreateAmqpPropertyValueFromNetProperty(
object? propertyValue,
out object? amqpPropertyValue,
bool allowBodyTypes = false)
{
amqpPropertyValue = null;
if (propertyValue == null)
{
return true;
}
switch (GetTypeIdentifier(propertyValue))
{
case AmqpType.Byte:
case AmqpType.SByte:
case AmqpType.Int16:
case AmqpType.Int32:
case AmqpType.Int64:
case AmqpType.UInt16:
case AmqpType.UInt32:
case AmqpType.UInt64:
case AmqpType.Single:
case AmqpType.Double:
case AmqpType.Boolean:
case AmqpType.Decimal:
case AmqpType.Char:
case AmqpType.Guid:
case AmqpType.DateTime:
case AmqpType.String:
amqpPropertyValue = propertyValue;
break;
case AmqpType.Stream:
case AmqpType.Unknown when propertyValue is Stream:
amqpPropertyValue = ReadStreamToArraySegment((Stream)propertyValue);
break;
case AmqpType.Uri:
amqpPropertyValue = new DescribedType((AmqpSymbol)AmqpMessageConstants.Uri, ((Uri)propertyValue).AbsoluteUri);
break;
case AmqpType.DateTimeOffset:
amqpPropertyValue = new DescribedType((AmqpSymbol)AmqpMessageConstants.DateTimeOffset, ((DateTimeOffset)propertyValue).UtcTicks);
break;
case AmqpType.TimeSpan:
amqpPropertyValue = new DescribedType((AmqpSymbol)AmqpMessageConstants.TimeSpan, ((TimeSpan)propertyValue).Ticks);
break;
case AmqpType.Unknown when allowBodyTypes && propertyValue is byte[] byteArray:
amqpPropertyValue = new ArraySegment<byte>(byteArray);
break;
case AmqpType.Unknown when allowBodyTypes && propertyValue is IDictionary dict:
amqpPropertyValue = new AmqpMap(dict);
break;
case AmqpType.Unknown when allowBodyTypes && propertyValue is IList:
amqpPropertyValue = propertyValue;
break;
case AmqpType.Unknown:
var exception = new SerializationException(string.Format(CultureInfo.CurrentCulture, "Serialization failed due to an unsupported type, {0}.", propertyValue.GetType().FullName));
throw exception;
}
return (amqpPropertyValue != null);
}