From db5512db591bb45d6d57c9644ae66776162dccb2 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 17 Jan 2021 00:52:01 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=8E=20De-Linqify=20ToConnectionString?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Item for #12 --- X10D/src/DictionaryExtensions.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/X10D/src/DictionaryExtensions.cs b/X10D/src/DictionaryExtensions.cs index 359a81b..3e87521 100644 --- a/X10D/src/DictionaryExtensions.cs +++ b/X10D/src/DictionaryExtensions.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Web; @@ -19,6 +20,11 @@ namespace X10D /// Returns a representing the dictionary as a key=value; set. public static string ToConnectionString(this IReadOnlyDictionary dictionary) { + if (dictionary is null) + { + throw new ArgumentNullException(nameof(dictionary)); + } + static string SanitizeValue(string? value) { if (value is null) @@ -37,8 +43,14 @@ namespace X10D return value; } - var strings = dictionary.Select(o => $"{o.Key}={SanitizeValue(o.Value?.ToString())}"); - return string.Join(";", strings); + var list = new List(); + + foreach (var pair in dictionary) + { + list.Add($"{pair.Key}={SanitizeValue(pair.Value?.ToString())}"); + } + + return string.Join(";", list); } ///