From f6a006c90da5877f19c7e67c473dca125dc51beb Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Fri, 14 Jul 2017 12:24:53 -0400 Subject: [PATCH] Fixing null ref in array formatting --- ICD.Common.Utils/StringUtils.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ICD.Common.Utils/StringUtils.cs b/ICD.Common.Utils/StringUtils.cs index e339eaf..4acac1c 100644 --- a/ICD.Common.Utils/StringUtils.cs +++ b/ICD.Common.Utils/StringUtils.cs @@ -115,6 +115,16 @@ namespace ICD.Common.Utils return string.Join("", strings); } + /// + /// Uses String.Format to properly handle null values. + /// + /// + /// + public static string ToString(object value) + { + return string.Format("{0}", value); + } + /// /// Converts bytes to an ascii string. /// @@ -360,7 +370,7 @@ namespace ICD.Common.Utils if (items == null) throw new ArgumentNullException("items"); - return string.Format("[{0}]", string.Join(", ", items.Select(i => i.ToString()).ToArray())); + return string.Format("[{0}]", string.Join(", ", items.Select(i => ToString(i)).ToArray())); } /// @@ -377,7 +387,7 @@ namespace ICD.Common.Utils string[] ranges = MathUtils.GetRanges(items) .Select(r => r[0] == r[1] - ? r[0].ToString() + ? ToString(r[0]) : string.Format("{0}-{1}", r[0], r[1])) .ToArray();