From 95495ac334199ee510b10e9ff72a94b0544a3681 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sun, 25 Jul 2021 08:48:25 -0400 Subject: [PATCH] add ToNullTerminatedArray function (for P/Invoke interop) --- MBS.Framework/Collections/Generic/ExtensionMethods.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/MBS.Framework/Collections/Generic/ExtensionMethods.cs b/MBS.Framework/Collections/Generic/ExtensionMethods.cs index 971c542..3af9203 100644 --- a/MBS.Framework/Collections/Generic/ExtensionMethods.cs +++ b/MBS.Framework/Collections/Generic/ExtensionMethods.cs @@ -62,5 +62,16 @@ namespace MBS.Framework.Collections.Generic list.Add(item); } } + + public static T[] ToNullTerminatedArray(this IEnumerable enumerable) where T : class + { + List list = new List(); + foreach (T name in enumerable) + { + list.Add(name); + } + list.Add(null); + return list.ToArray(); + } } }