1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-23 01:28:48 +00:00

🐎 De-Linqify ToConnectionString

Item for #12
This commit is contained in:
Oliver Booth 2021-01-17 00:52:01 +00:00
parent 3ad20fdb40
commit db5512db59

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Web; using System.Web;
@ -19,6 +20,11 @@ namespace X10D
/// <returns>Returns a <see cref="string" /> representing the dictionary as a key=value; set.</returns> /// <returns>Returns a <see cref="string" /> representing the dictionary as a key=value; set.</returns>
public static string ToConnectionString<T1, T2>(this IReadOnlyDictionary<T1, T2> dictionary) public static string ToConnectionString<T1, T2>(this IReadOnlyDictionary<T1, T2> dictionary)
{ {
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}
static string SanitizeValue(string? value) static string SanitizeValue(string? value)
{ {
if (value is null) if (value is null)
@ -37,8 +43,14 @@ namespace X10D
return value; return value;
} }
var strings = dictionary.Select(o => $"{o.Key}={SanitizeValue(o.Value?.ToString())}"); var list = new List<string>();
return string.Join(";", strings);
foreach (var pair in dictionary)
{
list.Add($"{pair.Key}={SanitizeValue(pair.Value?.ToString())}");
}
return string.Join(";", list);
} }
/// <summary> /// <summary>