mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 03:57:32 +00:00
feat: Added ToCollection extension method for copying an enumerable to a new collection
This commit is contained in:
parent
d07373b69e
commit
75ddc37cf1
2 changed files with 23 additions and 0 deletions
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue