From c80020956f90053753026f4e7cb7a1e96f14570a Mon Sep 17 00:00:00 2001 From: AJ Date: Thu, 21 Nov 2019 14:49:57 -0500 Subject: [PATCH] Moved PunctuateList method to Extensions class --- ExportDXF/Extensions.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ExportDXF/Extensions.cs b/ExportDXF/Extensions.cs index 47dcaa3..a628f0e 100644 --- a/ExportDXF/Extensions.cs +++ b/ExportDXF/Extensions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Drawing; using System.Text; using System.Windows.Forms; @@ -41,5 +42,32 @@ namespace ExportDXF return s.ToString(); } + + public static string PunctuateList(this IEnumerable stringList) + { + var list = stringList.ToList(); + + switch (list.Count) + { + case 0: + return string.Empty; + + case 1: + return list[0]; + + case 2: + return string.Format("{0} and {1}", list[0], list[1]); + + default: + var s = string.Empty; + + for (int i = 0; i < list.Count - 1; i++) + s += list[i] + ", "; + + s += "and " + list.Last(); + + return s; + } + } } } \ No newline at end of file