7public static class SimpleRestExtensions
9 public static object? SafeDeserialize(
this string json,
object fallbackValue, JsonSerializerOptions options)
13 return JsonSerializer.Deserialize<
object?>(json);
21 public static Uri.UriTemplate IgnoreTrailingSlash(
this Uri.UriTemplate uriTemplate)
23 return new Uri.UriTemplate(uriTemplate.Template.TrimEnd(
'/'));
26 public static WebHeaderCollection ToWebHeaderCollection(
27 this Dictionary<string, string> dictionary
30 WebHeaderCollection webHeaderCollection =
new WebHeaderCollection();
31 foreach (KeyValuePair<string, string> kvp
in dictionary)
33 webHeaderCollection.Add(kvp.Key, kvp.Value);
35 return webHeaderCollection;
38 public static void Merge<Tkey, TValue>(
39 this Dictionary<Tkey, TValue> dictionary,
40 Dictionary<Tkey, TValue> dictionaryToMerge
44 foreach (var kvp
in dictionaryToMerge)
47 dictionary[kvp.Key] = kvp.Value;
55 public static void NonDistructiveUnion<TKey, TValue>(
56 this Dictionary<TKey, TValue> target,
57 Dictionary<TKey, TValue> source
61 foreach (var kvp
in source)
64 if (!target.ContainsKey(kvp.Key))
66 target[kvp.Key] = kvp.Value;