feat: Added Collection extensions for setting and adding ranges of items

This commit is contained in:
Chris Cameron
2020-07-16 12:13:57 -04:00
parent 449bd41cb3
commit 816f8984be
3 changed files with 52 additions and 0 deletions

View File

@@ -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

View 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);
}
}
}

View File

@@ -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" />