diff --git a/ICD.Common.Utils/Extensions/AssemblyExtensions.cs b/ICD.Common.Utils/Extensions/AssemblyExtensions.cs
index fafd5a9..4f87c1c 100644
--- a/ICD.Common.Utils/Extensions/AssemblyExtensions.cs
+++ b/ICD.Common.Utils/Extensions/AssemblyExtensions.cs
@@ -18,7 +18,7 @@ namespace ICD.Common.Utils.Extensions
///
///
[CanBeNull]
- public static string GetPath(this Assembly extends)
+ public static string GetPath([NotNull]this Assembly extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -29,7 +29,7 @@ namespace ICD.Common.Utils.Extensions
#endif
.CodeBase;
- if (path == null)
+ if (string.IsNullOrEmpty(path))
{
#if STANDARD
path = extends.Location;
@@ -51,7 +51,7 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static DateTime GetCreationTime(this Assembly extends)
+ public static DateTime GetCreationTime([NotNull]this Assembly extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -66,7 +66,7 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static string GetInformationalVersion(this Assembly extends)
+ public static string GetInformationalVersion([NotNull]this Assembly extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -85,7 +85,7 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static bool TryGetInformationalVersion(this Assembly extends, out string version)
+ public static bool TryGetInformationalVersion([NotNull]this Assembly extends, out string version)
{
if (extends == null)
throw new ArgumentNullException("extends");
diff --git a/ICD.Common.Utils/Extensions/CultureInfoExtensions.cs b/ICD.Common.Utils/Extensions/CultureInfoExtensions.cs
index 20f9053..3fb4ff0 100644
--- a/ICD.Common.Utils/Extensions/CultureInfoExtensions.cs
+++ b/ICD.Common.Utils/Extensions/CultureInfoExtensions.cs
@@ -1,5 +1,6 @@
using System;
using System.Globalization;
+using ICD.Common.Properties;
namespace ICD.Common.Utils.Extensions
{
@@ -10,7 +11,7 @@ namespace ICD.Common.Utils.Extensions
///
///
///
- public static bool Uses24HourFormat(this CultureInfo extends)
+ public static bool Uses24HourFormat([NotNull]this CultureInfo extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -22,7 +23,7 @@ namespace ICD.Common.Utils.Extensions
/// Updates the time patterns for the given culture to use 12 hour time.
///
///
- public static void ConvertTo12HourCulture(this CultureInfo extends)
+ public static void ConvertTo12HourCulture([NotNull]this CultureInfo extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -41,7 +42,7 @@ namespace ICD.Common.Utils.Extensions
/// Updates the time patterns for the given culture to use 24 hour time.
///
///
- public static void ConvertTo24HourCulture(this CultureInfo extends)
+ public static void ConvertTo24HourCulture([NotNull]this CultureInfo extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
diff --git a/ICD.Common.Utils/Extensions/DateTimeExtensions.cs b/ICD.Common.Utils/Extensions/DateTimeExtensions.cs
index acdc661..6fde0be 100644
--- a/ICD.Common.Utils/Extensions/DateTimeExtensions.cs
+++ b/ICD.Common.Utils/Extensions/DateTimeExtensions.cs
@@ -58,7 +58,7 @@ namespace ICD.Common.Utils.Extensions
public static DateTime? PreviousLatestTime(this DateTime target, bool inclusive, params DateTime[] times)
{
if (times == null)
- throw new ArgumentNullException("null");
+ throw new ArgumentNullException("times");
DateTime latestTime;
bool success = times.OrderByDescending(dt => dt).TryFirst(dt => inclusive ? target >= dt : target > dt, out latestTime);
diff --git a/ICD.Common.Utils/Extensions/DictionaryExtensions.cs b/ICD.Common.Utils/Extensions/DictionaryExtensions.cs
index 58bf7f8..7bcb3df 100644
--- a/ICD.Common.Utils/Extensions/DictionaryExtensions.cs
+++ b/ICD.Common.Utils/Extensions/DictionaryExtensions.cs
@@ -14,7 +14,8 @@ namespace ICD.Common.Utils.Extensions
///
///
///
- public static void RemoveAll(this IDictionary extends, IEnumerable keys)
+ public static void RemoveAll([NotNull] this IDictionary extends,
+ [NotNull] IEnumerable keys)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -35,7 +36,7 @@ namespace ICD.Common.Utils.Extensions
///
/// False if value is not found in the dictionary.
[PublicAPI]
- public static bool RemoveValue(this IDictionary extends, TValue value)
+ public static bool RemoveValue([NotNull] this IDictionary extends, TValue value)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -52,7 +53,7 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static void RemoveAllValues(this IDictionary extends, TValue value)
+ public static void RemoveAllValues([NotNull] this IDictionary extends, TValue value)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -71,12 +72,12 @@ namespace ICD.Common.Utils.Extensions
///
[CanBeNull]
[PublicAPI]
- public static TValue GetDefault(this IDictionary extends, TKey key)
+ public static TValue GetDefault([NotNull] this IDictionary extends,
+ [NotNull] TKey key)
{
if (extends == null)
throw new ArgumentNullException("extends");
- // ReSharper disable once CompareNonConstrainedGenericWithNull
if (key == null)
throw new ArgumentNullException("key");
@@ -93,12 +94,13 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static TValue GetDefault(this IDictionary extends, TKey key, TValue defaultValue)
+ public static TValue GetDefault([NotNull] this IDictionary extends,
+ [NotNull] TKey key,
+ TValue defaultValue)
{
if (extends == null)
throw new ArgumentNullException("extends");
- // ReSharper disable once CompareNonConstrainedGenericWithNull
if (key == null)
throw new ArgumentNullException("key");
@@ -116,13 +118,13 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static TValue GetOrAddDefault(this IDictionary extends, TKey key,
+ public static TValue GetOrAddDefault([NotNull] this IDictionary extends,
+ [NotNull] TKey key,
TValue defaultValue)
{
if (extends == null)
throw new ArgumentNullException("extends");
- // ReSharper disable once CompareNonConstrainedGenericWithNull
if (key == null)
throw new ArgumentNullException("key");
@@ -141,7 +143,8 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static TValue GetOrAddNew(this IDictionary extends, TKey key)
+ public static TValue GetOrAddNew([NotNull] this IDictionary extends,
+ [NotNull] TKey key)
where TValue : new()
{
if (extends == null)
@@ -165,7 +168,9 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static TValue GetOrAddNew(this IDictionary extends, TKey key, Func valueFunc)
+ public static TValue GetOrAddNew([NotNull] this IDictionary extends,
+ [NotNull] TKey key,
+ [NotNull] Func valueFunc)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -175,6 +180,9 @@ namespace ICD.Common.Utils.Extensions
// ReSharper restore CompareNonConstrainedGenericWithNull
throw new ArgumentNullException("key");
+ if (valueFunc == null)
+ throw new ArgumentNullException("valueFunc");
+
TValue value;
if (!extends.TryGetValue(key, out value))
{
@@ -195,7 +203,7 @@ namespace ICD.Common.Utils.Extensions
///
/// The value does not exist in the dictionary.
[PublicAPI]
- public static TKey GetKey(this IDictionary extends, TValue value)
+ public static TKey GetKey([NotNull] this IDictionary extends, TValue value)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -218,7 +226,8 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static bool TryGetKey(this IDictionary extends, TValue value, out TKey key)
+ public static bool TryGetKey([NotNull] this IDictionary extends, TValue value,
+ out TKey key)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -235,7 +244,8 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static IEnumerable GetKeys(this IDictionary extends, TValue value)
+ public static IEnumerable GetKeys([NotNull] this IDictionary extends,
+ TValue value)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -253,8 +263,8 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static bool Update(this IDictionary extends,
- IEnumerable> other)
+ public static bool Update([NotNull] this IDictionary extends,
+ [NotNull] IEnumerable> other)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -275,9 +285,9 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static bool Update(this IDictionary extends,
- IEnumerable> other,
- IEqualityComparer comparer)
+ public static bool Update([NotNull] this IDictionary extends,
+ [NotNull] IEnumerable> other,
+ [NotNull] IEqualityComparer comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -285,6 +295,9 @@ namespace ICD.Common.Utils.Extensions
if (other == null)
throw new ArgumentNullException("other");
+ if (comparer == null)
+ throw new ArgumentNullException("comparer");
+
bool change = false;
foreach (KeyValuePair pair in other)
@@ -308,7 +321,8 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static void AddRange(this IDictionary extends, IEnumerable> items)
+ public static void AddRange([NotNull] this IDictionary extends,
+ [NotNull] IEnumerable> items)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -329,8 +343,9 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static void AddRange(this IDictionary extends, IEnumerable items,
- Func getKey)
+ public static void AddRange([NotNull] this IDictionary extends,
+ [NotNull] IEnumerable items,
+ [NotNull] Func getKey)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -354,8 +369,9 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static void AddRange(this IDictionary extends, IEnumerable items,
- Func getValue)
+ public static void AddRange([NotNull] this IDictionary extends,
+ [NotNull] IEnumerable items,
+ [NotNull] Func getValue)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -378,8 +394,8 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static void AddRange(this Dictionary extends,
- IEnumerable> items)
+ public static void AddRange([NotNull] this Dictionary extends,
+ [NotNull] IEnumerable> items)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -400,12 +416,15 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static bool DictionaryEqual(this IDictionary extends,
- IDictionary other)
+ public static bool DictionaryEqual([NotNull] this IDictionary extends,
+ [NotNull] IDictionary other)
{
if (extends == null)
throw new ArgumentNullException("extends");
+ if (other == null)
+ throw new ArgumentNullException("other");
+
return extends.DictionaryEqual(other, EqualityComparer.Default);
}
@@ -419,13 +438,16 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static bool DictionaryEqual(this IDictionary extends,
- IDictionary other,
- IEqualityComparer valueComparer)
+ public static bool DictionaryEqual([NotNull] this IDictionary extends,
+ [NotNull] IDictionary other,
+ [NotNull] IEqualityComparer valueComparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
+ if (other == null)
+ throw new ArgumentNullException("other");
+
if (valueComparer == null)
throw new ArgumentNullException("valueComparer");
@@ -442,20 +464,21 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static bool DictionaryEqual(this IDictionary extends,
- IDictionary other,
- Func valueComparer)
+ public static bool DictionaryEqual([NotNull] this IDictionary extends,
+ [NotNull] IDictionary other,
+ [NotNull] Func valueComparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
+ if (other == null)
+ throw new ArgumentNullException("other");
+
if (valueComparer == null)
throw new ArgumentNullException("valueComparer");
if (extends == other)
return true;
- if (other == null)
- return false;
if (extends.Count != other.Count)
return false;
@@ -467,6 +490,7 @@ namespace ICD.Common.Utils.Extensions
if (!valueComparer(kvp.Value, secondValue))
return false;
}
+
return true;
}
@@ -479,7 +503,7 @@ namespace ICD.Common.Utils.Extensions
///
[PublicAPI]
public static IEnumerable> OrderByKey(
- this IEnumerable> extends)
+ [NotNull] this IEnumerable> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -495,7 +519,8 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static IEnumerable OrderValuesByKey(this IEnumerable> extends)
+ public static IEnumerable OrderValuesByKey(
+ [NotNull] this IEnumerable> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -511,7 +536,8 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static Dictionary> ToInverse(this IEnumerable> extends)
+ public static Dictionary> ToInverse(
+ [NotNull] this IEnumerable> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -532,5 +558,22 @@ namespace ICD.Common.Utils.Extensions
return output;
}
+
+ ///
+ /// Turns an enumerable of KeyValuePairs back into a dictionary
+ ///
+ ///
+ ///
+ ///
+ ///
+ [PublicAPI]
+ public static Dictionary ToDictionary(
+ [NotNull] this IEnumerable> extends)
+ {
+ if (extends == null)
+ throw new ArgumentNullException("extends");
+
+ return extends.ToDictionary(x => x.Key, x => x.Value);
+ }
}
}
diff --git a/ICD.Common.Utils/Extensions/EnumerableExtensions.cs b/ICD.Common.Utils/Extensions/EnumerableExtensions.cs
index ada0f46..1cfb944 100644
--- a/ICD.Common.Utils/Extensions/EnumerableExtensions.cs
+++ b/ICD.Common.Utils/Extensions/EnumerableExtensions.cs
@@ -17,7 +17,7 @@ namespace ICD.Common.Utils.Extensions
///
///
///
- public static T FirstOrDefault(this IEnumerable extends, T defaultItem)
+ public static T FirstOrDefault([NotNull] this IEnumerable extends, T defaultItem)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -34,7 +34,8 @@ namespace ICD.Common.Utils.Extensions
///
///
///
- public static T FirstOrDefault(this IEnumerable extends, Func predicate, T defaultItem)
+ public static T FirstOrDefault([NotNull] this IEnumerable extends, [NotNull] Func predicate,
+ T defaultItem)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -53,7 +54,7 @@ namespace ICD.Common.Utils.Extensions
///
/// Outputs the first item in the sequence.
///
- public static bool TryFirst(this IEnumerable extends, out T item)
+ public static bool TryFirst([NotNull] this IEnumerable extends, out T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -80,7 +81,8 @@ namespace ICD.Common.Utils.Extensions
///
/// Outputs the first item in the sequence.
///
- public static bool TryFirst(this IEnumerable extends, Func predicate, out T item)
+ public static bool TryFirst([NotNull] this IEnumerable extends, [NotNull] Func predicate,
+ out T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -112,7 +114,7 @@ namespace ICD.Common.Utils.Extensions
///
/// Outputs the last item in the sequence.
///
- public static bool TryLast(this IEnumerable extends, out T item)
+ public static bool TryLast([NotNull] this IEnumerable extends, out T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -139,7 +141,8 @@ namespace ICD.Common.Utils.Extensions
///
/// Outputs the last item in the sequence.
///
- public static bool TryLast(this IEnumerable extends, Func predicate, out T item)
+ public static bool TryLast([NotNull] this IEnumerable extends, [NotNull] Func predicate,
+ out T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -173,7 +176,7 @@ namespace ICD.Common.Utils.Extensions
///
///
///
- public static bool TryElementAt(this IEnumerable extends, int index, out T item)
+ public static bool TryElementAt([NotNull] this IEnumerable extends, int index, out T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -200,6 +203,7 @@ namespace ICD.Common.Utils.Extensions
item = value;
return true;
}
+
current++;
}
@@ -214,7 +218,7 @@ namespace ICD.Common.Utils.Extensions
///
///
///
- public static T ElementAtOrDefault(this IEnumerable extends, int index, T defaultValue)
+ public static T ElementAtOrDefault([NotNull] this IEnumerable extends, int index, T defaultValue)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -231,7 +235,8 @@ namespace ICD.Common.Utils.Extensions
///
///
///
- public static bool SequenceEqual(this IEnumerable extends, IEnumerable other, IEqualityComparer comparer)
+ public static bool SequenceEqual([NotNull] this IEnumerable extends, [NotNull] IEnumerable other,
+ [NotNull] IEqualityComparer comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -253,7 +258,8 @@ namespace ICD.Common.Utils.Extensions
///
///
///
- public static bool SequenceEqual(this IEnumerable extends, IEnumerable other, Func comparer)
+ public static bool SequenceEqual([NotNull] this IEnumerable extends, [NotNull] IEnumerable other,
+ [NotNull] Func comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -298,7 +304,7 @@ namespace ICD.Common.Utils.Extensions
///
///
///
- public static bool ScrambledEquals(this IEnumerable extends, IEnumerable other)
+ public static bool ScrambledEquals([NotNull] this IEnumerable extends, [NotNull] IEnumerable other)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -317,7 +323,8 @@ namespace ICD.Common.Utils.Extensions
///
///
///
- public static bool ScrambledEquals(this IEnumerable extends, IEnumerable other, IEqualityComparer comparer)
+ public static bool ScrambledEquals([NotNull] this IEnumerable extends, [NotNull] IEnumerable other,
+ [NotNull] IEqualityComparer comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -352,7 +359,7 @@ namespace ICD.Common.Utils.Extensions
///
///
///
- public static int FindIndex(this IEnumerable extends, Predicate match)
+ public static int FindIndex([NotNull] this IEnumerable extends, [NotNull] Predicate match)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -370,7 +377,8 @@ namespace ICD.Common.Utils.Extensions
///
///
///
- public static IEnumerable FindIndices(this IEnumerable extends, Predicate match)
+ public static IEnumerable FindIndices([NotNull] this IEnumerable extends,
+ [NotNull] Predicate match)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -388,7 +396,8 @@ namespace ICD.Common.Utils.Extensions
///
///
///
- private static IEnumerable FindIndicesIterator(IEnumerable sequence, Predicate match)
+ private static IEnumerable FindIndicesIterator([NotNull] IEnumerable sequence,
+ [NotNull] Predicate match)
{
int index = 0;
@@ -408,7 +417,8 @@ namespace ICD.Common.Utils.Extensions
///
///
///
- public static IEnumerable SelectMulti(this IEnumerable extends,
+ public static IEnumerable SelectMulti([NotNull] this IEnumerable extends,
+ [NotNull]
params Func[] selectors)
{
if (extends == null)
@@ -427,7 +437,7 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static void Execute(this IEnumerable extends)
+ public static void Execute([NotNull] this IEnumerable extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -446,7 +456,7 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static void ForEach(this IEnumerable extends, Action action)
+ public static void ForEach([NotNull] this IEnumerable extends, [NotNull] Action action)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -464,7 +474,7 @@ namespace ICD.Common.Utils.Extensions
///
///
[PublicAPI]
- public static void ForEach(this IEnumerable extends, Action action)
+ public static void ForEach([NotNull] this IEnumerable extends, [NotNull] Action action)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -485,7 +495,7 @@ namespace ICD.Common.Utils.Extensions
///
///
///
- public static IEnumerable Prepend(this IEnumerable extends, T item)
+ public static IEnumerable Prepend([NotNull]this IEnumerable extends, T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -500,7 +510,7 @@ namespace ICD.Common.Utils.Extensions
///