diff --git a/src/WireMock.Net.Abstractions/Types/WireMockList.cs b/src/WireMock.Net.Abstractions/Types/WireMockList.cs
index d85e51dc5..28f410407 100644
--- a/src/WireMock.Net.Abstractions/Types/WireMockList.cs
+++ b/src/WireMock.Net.Abstractions/Types/WireMockList.cs
@@ -1,44 +1,69 @@
-using System.Collections.Generic;
-using System.Linq;
+using System.Collections.Generic;
-namespace WireMock.Types
+namespace WireMock.Types;
+
+///
+/// A special List which overrides the ToString() to return first value.
+///
+/// The generic type
+///
+public class WireMockList : List
{
///
- /// A special List which overrides the ToString() to return first value.
+ /// Initializes a new instance of the class.
///
- /// The generic type
- ///
- public class WireMockList : List
+ public WireMockList()
{
- ///
- /// Initializes a new instance of the class.
- ///
- public WireMockList()
- {
- }
+ }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The collection whose elements are copied to the new list.
- public WireMockList(params T[] collection) : base(collection)
- {
- }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The collection whose elements are copied to the new list.
+ public WireMockList(params T[] collection) : base(collection)
+ {
+ }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The collection whose elements are copied to the new list.
- public WireMockList(IEnumerable collection) : base(collection)
- {
- }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The collection whose elements are copied to the new list.
+ public WireMockList(IEnumerable collection) : base(collection)
+ {
+ }
+
+ ///
+ /// Operator for setting T
+ ///
+ /// The value to set.
+ public static implicit operator WireMockList(T value) => new(value);
+
+ ///
+ /// Operator for setting T[]
+ ///
+ /// The values to set.
+ public static implicit operator WireMockList(T[] values) => new(values);
- ///
- /// Returns a that represents this instance.
- ///
- public override string ToString()
+ ///
+ /// Returns a that represents this instance.
+ ///
+ public override string ToString()
+ {
+ switch (Count)
{
- return this.Any() ? this.First().ToString() : base.ToString();
+ case 0:
+ return string.Empty;
+
+ case 1:
+ if (this[0] is string strValue)
+ {
+ return strValue;
+ }
+
+ return this[0]?.ToString();
+
+ default:
+ return base.ToString();
}
}
}
\ No newline at end of file
diff --git a/src/WireMock.Net/ResponseMessage.cs b/src/WireMock.Net/ResponseMessage.cs
index 76fc9971b..e1c258b2f 100644
--- a/src/WireMock.Net/ResponseMessage.cs
+++ b/src/WireMock.Net/ResponseMessage.cs
@@ -39,7 +39,7 @@ public class ResponseMessage : IResponseMessage
public void AddHeader(string name, string value)
{
Headers ??= new Dictionary>();
- Headers.Add(name, new WireMockList(value));
+ Headers.Add(name, value);
}
///
@@ -52,6 +52,6 @@ public void AddHeader(string name, params string[] values)
? values.Union(existingValues).ToArray()
: values;
- Headers[name] = new WireMockList(newHeaderValues);
+ Headers[name] = newHeaderValues;
}
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Serialization/MappingConverter.cs b/src/WireMock.Net/Serialization/MappingConverter.cs
index 5f2460a60..d2ff126cc 100644
--- a/src/WireMock.Net/Serialization/MappingConverter.cs
+++ b/src/WireMock.Net/Serialization/MappingConverter.cs
@@ -251,8 +251,15 @@ private static IDictionary MapHeaders(IDictionary();
foreach (var entry in dictionary)
{
- object value = entry.Value.Count == 1 ? entry.Value.ToString() : entry.Value;
- newDictionary.Add(entry.Key, value);
+ // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
+ if (entry.Value.Count == 1)
+ {
+ newDictionary.Add(entry.Key, entry.Value.ToString());
+ }
+ else
+ {
+ newDictionary.Add(entry.Key, entry.Value);
+ }
}
return newDictionary;