mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
feat: Added ToCollection extension method for copying an enumerable to a new collection
This commit is contained in:
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- Added ToCollection extension method for copying an enumerable to a new collection
|
||||
|
||||
## [11.0.0] - 2020-03-20
|
||||
### Added
|
||||
- Added Not null tag for ICDUriBuilder Constructor that takes a URI as an argument.
|
||||
|
||||
@@ -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