2021-08-24 12:07:09 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Common.Extensions
|
|
|
|
|
{
|
|
|
|
|
public static class StringToolsExtensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add a string to a list only if it doesnt already exist
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void AddUnique(this IList<string> self, string item)
|
|
|
|
|
{
|
|
|
|
|
if (!self.Contains(item))
|
|
|
|
|
self.Add(item);
|
|
|
|
|
}
|
2021-08-25 20:08:13 +01:00
|
|
|
|
|
2023-08-15 09:29:16 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add a string to a list only if it doesnt already exist
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void AddUnique(this IDictionary<string, int> self, string itemkey, int weight)
|
|
|
|
|
{
|
|
|
|
|
if (!self.ContainsKey(itemkey))
|
|
|
|
|
self.Add(itemkey, weight);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-25 20:08:13 +01:00
|
|
|
|
public static void AddUniqueRange(this IList<string> self, IList<string> itemsToAdd)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in itemsToAdd)
|
|
|
|
|
{
|
|
|
|
|
if (!self.Contains(item))
|
|
|
|
|
self.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-24 12:07:09 +01:00
|
|
|
|
}
|
|
|
|
|
}
|