mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-13 03:35:04 +00:00
feat: Added Collection extensions for setting and adding ranges of items
This commit is contained in:
@@ -5,8 +5,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- Added Get and Set extensions to PropertyInfo in SIMPLSHARP to mimic overloads avaliable in NETSTANDARD
|
||||
- Added Collection extensions for setting and adding ranges of items
|
||||
|
||||
### Changed
|
||||
- Repeater changed to use configured callbacks instead of a dumb event
|
||||
- Scheduled action callbacks allow a TimeSpan to be returned to delay actions
|
||||
|
||||
## [12.1.0] - 2020-07-14
|
||||
### Added
|
||||
|
||||
45
ICD.Common.Utils/Extensions/CollectionExtensions.cs
Normal file
45
ICD.Common.Utils/Extensions/CollectionExtensions.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ICD.Common.Properties;
|
||||
|
||||
namespace ICD.Common.Utils.Extensions
|
||||
{
|
||||
public static class CollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Clears the collection and adds the given range of items.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="extends"></param>
|
||||
/// <param name="range"></param>
|
||||
public static void SetRange<T>([NotNull] this ICollection<T> extends, [NotNull] IEnumerable<T> range)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
if (range == null)
|
||||
throw new ArgumentNullException("range");
|
||||
|
||||
extends.Clear();
|
||||
extends.AddRange(range);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given range of items to the collection.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="extends"></param>
|
||||
/// <param name="range"></param>
|
||||
public static void AddRange<T>([NotNull] this ICollection<T> extends, [NotNull] IEnumerable<T> range)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
if (range == null)
|
||||
throw new ArgumentNullException("range");
|
||||
|
||||
foreach (T item in range)
|
||||
extends.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,6 +109,7 @@
|
||||
<None Include="CultureInfo.sqlite">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Compile Include="Extensions\CollectionExtensions.cs" />
|
||||
<Compile Include="ObfuscationSettings.cs" />
|
||||
<Compile Include="Extensions\BoolExtensions.cs" />
|
||||
<Compile Include="Extensions\ByteExtensions.cs" />
|
||||
|
||||
Reference in New Issue
Block a user