mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-14 12:15:05 +00:00
feat: Added ToCollection extension method for copying an enumerable to a new collection
This commit is contained in:
@@ -838,6 +838,26 @@ namespace ICD.Common.Utils.Extensions
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new collection and fills it with the items of the enumerable.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TCollection"></typeparam>
|
||||
/// <param name="extends"></param>
|
||||
/// <returns></returns>
|
||||
public static TCollection ToCollection<T, TCollection>([NotNull] this IEnumerable<T> extends)
|
||||
where TCollection : ICollection<T>
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
TCollection collection = ReflectionUtils.CreateInstance<TCollection>();
|
||||
foreach (T item in extends)
|
||||
collection.Add(item);
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the sequence as a IcdHashSet.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user