| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. See License.txt in the project root for |
| | | 3 | | // license information. |
| | | 4 | | |
| | | 5 | | namespace Microsoft.Azure.Search.Common |
| | | 6 | | { |
| | | 7 | | using System; |
| | | 8 | | using System.Collections.Generic; |
| | | 9 | | using System.Linq; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Defines extension methods for IEnumerable that are used in the implementation of the Azure Cognitive Search |
| | | 13 | | /// .NET SDK. |
| | | 14 | | /// </summary> |
| | | 15 | | public static class EnumerableExtensions |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// Converts the elements of a collection to strings and concatenates them into a comma-separated list, |
| | | 19 | | /// or returns null for null or empty collections. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <typeparam name="T">The type of elements that will be converted to strings.</typeparam> |
| | | 22 | | /// <param name="enumerable">The collection to turn into a comma-separated string.</param> |
| | | 23 | | /// <returns>A comma-separated string, or null if enumerable is null or empty.</returns> |
| | | 24 | | public static string ToCommaSeparatedString<T>(this IEnumerable<T> enumerable) |
| | | 25 | | { |
| | 624 | 26 | | if (enumerable == null || !enumerable.Any()) |
| | | 27 | | { |
| | 414 | 28 | | return null; |
| | | 29 | | } |
| | | 30 | | |
| | 198 | 31 | | return String.Join(",", enumerable); |
| | | 32 | | } |
| | | 33 | | } |
| | | 34 | | } |