-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathListUtils.cs
More file actions
64 lines (59 loc) · 2.13 KB
/
ListUtils.cs
File metadata and controls
64 lines (59 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hansoft.ObjectWrapper
{
/// <summary>
/// Utilities for formatting lists of Hansoft Items for display.
/// </summary>
public class ListUtils
{
/// <summary>
/// Create a comma separated list (string) with the names of a list of HansoftItems
/// </summary>
/// <param name="items">The items to format.</param>
/// <returns>A formatted string suitable for display.</returns>
public static string ToString(IEnumerable<HansoftItem> items)
{
return ListUtils.ToString(items, ',');
}
/// <summary>
/// Create a list (string) with the names of a list of HansoftItems. The items will be separated by the specified character.
/// </summary>
/// <param name="items">The items to format.</param>
/// <param name="separator">The separator ro use</param>
/// <returns>A formatted string suitable for display.</returns>
public static string ToString(IEnumerable<HansoftItem> items, char separator)
{
StringBuilder sb = new StringBuilder();
foreach (HansoftItem item in items)
{
if (sb.Length > 0)
{
sb.Append(separator);
sb.Append(' ');
}
sb.Append(item.Name);
}
return sb.ToString();
}
/// <summary>
/// Create a list (string) with the names of a list of HansoftItems.
/// </summary>
/// <param name="items">The items to format.</param>
/// <param name="separator">The separator ro use</param>
/// <returns>A formatted string suitable for display.</returns>
public static IList ToStringList(IEnumerable<HansoftItem> items)
{
IList list = new List<string>();
foreach (HansoftItem item in items)
{
list.Add(item.Name);
}
return list;
}
}
}