static void SetHeaders(IDictionary <string, object> dictionary, SendHeaders headers) { foreach (KeyValuePair <string, object> header in headers.GetAll()) { if (header.Value == null) { if (dictionary.ContainsKey(header.Key)) { dictionary.Remove(header.Key); } continue; } if (dictionary.ContainsKey(header.Key)) { continue; } switch (header.Value) { case DateTimeOffset value: if (_dateTimeOffsetConverter.TryConvert(value, out string text)) { dictionary[header.Key] = text; } break; case DateTime value: if (_dateTimeConverter.TryConvert(value, out text)) { dictionary[header.Key] = text; } break; case string value: dictionary[header.Key] = value; break; case bool value when value: dictionary[header.Key] = bool.TrueString; break; case IFormattable formatValue: if (header.Value.GetType().IsValueType) { dictionary[header.Key] = header.Value; } else { dictionary[header.Key] = formatValue.ToString(); } break; } } }
public static void SetHeaders(this IPrimitiveMap dictionary, SendHeaders headers) { foreach (KeyValuePair <string, object> header in headers.GetAll()) { if (header.Value == null) { if (dictionary.Contains(header.Key)) { dictionary.Remove(header.Key); } continue; } if (dictionary.Contains(header.Key)) { continue; } switch (header.Value) { case DateTimeOffset dateTimeOffset: if (_dateTimeOffsetConverter.TryConvert(dateTimeOffset, out long result)) { dictionary[header.Key] = result; } else if (_dateTimeOffsetConverter.TryConvert(dateTimeOffset, out string text)) { dictionary[header.Key] = text; } break; case DateTime dateTime: if (_dateTimeConverter.TryConvert(dateTime, out result)) { dictionary[header.Key] = result; } else if (_dateTimeConverter.TryConvert(dateTime, out string text)) { dictionary[header.Key] = text; } break; case string s: dictionary[header.Key] = s; break; case bool boolValue when boolValue: dictionary[header.Key] = bool.TrueString; break; case IFormattable formatValue: if (header.Value.GetType().IsValueType) { dictionary[header.Key] = header.Value; } else { dictionary[header.Key] = formatValue.ToString(); } break; } if (header.Key == "AMQ_SCHEDULED_DELAY") { headers.Set(header.Key, null); } } }