chore: Decorating extension methods with NotNull and CanBeNull attributes

This commit is contained in:
Chris Cameron
2019-10-07 21:59:21 -04:00
parent 38204314e7
commit 89cde5c9a0
20 changed files with 445 additions and 313 deletions

View File

@@ -18,7 +18,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[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
/// <param name="extends"></param>
/// <returns></returns>
[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
/// <param name="extends"></param>
/// <returns></returns>
[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
/// <param name="version"></param>
/// <returns></returns>
[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");

View File

@@ -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
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
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.
/// </summary>
/// <param name="extends"></param>
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.
/// </summary>
/// <param name="extends"></param>
public static void ConvertTo24HourCulture(this CultureInfo extends)
public static void ConvertTo24HourCulture([NotNull]this CultureInfo extends)
{
if (extends == null)
throw new ArgumentNullException("extends");

View File

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

View File

@@ -14,7 +14,8 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="TValue"></typeparam>
/// <param name="extends"></param>
/// <param name="keys"></param>
public static void RemoveAll<TKey, TValue>(this IDictionary<TKey, TValue> extends, IEnumerable<TKey> keys)
public static void RemoveAll<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends,
[NotNull] IEnumerable<TKey> keys)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -35,7 +36,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="value"></param>
/// <returns>False if value is not found in the dictionary.</returns>
[PublicAPI]
public static bool RemoveValue<TKey, TValue>(this IDictionary<TKey, TValue> extends, TValue value)
public static bool RemoveValue<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends, TValue value)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -52,7 +53,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="value"></param>
[PublicAPI]
public static void RemoveAllValues<TKey, TValue>(this IDictionary<TKey, TValue> extends, TValue value)
public static void RemoveAllValues<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends, TValue value)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -71,12 +72,12 @@ namespace ICD.Common.Utils.Extensions
/// <returns></returns>
[CanBeNull]
[PublicAPI]
public static TValue GetDefault<TKey, TValue>(this IDictionary<TKey, TValue> extends, TKey key)
public static TValue GetDefault<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> 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
/// <param name="defaultValue"></param>
/// <returns></returns>
[PublicAPI]
public static TValue GetDefault<TKey, TValue>(this IDictionary<TKey, TValue> extends, TKey key, TValue defaultValue)
public static TValue GetDefault<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> 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
/// <param name="defaultValue"></param>
/// <returns></returns>
[PublicAPI]
public static TValue GetOrAddDefault<TKey, TValue>(this IDictionary<TKey, TValue> extends, TKey key,
public static TValue GetOrAddDefault<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> 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
/// <param name="key"></param>
/// <returns></returns>
[PublicAPI]
public static TValue GetOrAddNew<TKey, TValue>(this IDictionary<TKey, TValue> extends, TKey key)
public static TValue GetOrAddNew<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends,
[NotNull] TKey key)
where TValue : new()
{
if (extends == null)
@@ -165,7 +168,9 @@ namespace ICD.Common.Utils.Extensions
/// <param name="valueFunc"></param>
/// <returns></returns>
[PublicAPI]
public static TValue GetOrAddNew<TKey, TValue>(this IDictionary<TKey, TValue> extends, TKey key, Func<TValue> valueFunc)
public static TValue GetOrAddNew<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends,
[NotNull] TKey key,
[NotNull] Func<TValue> 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
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException">The value does not exist in the dictionary.</exception>
[PublicAPI]
public static TKey GetKey<TKey, TValue>(this IDictionary<TKey, TValue> extends, TValue value)
public static TKey GetKey<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends, TValue value)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -218,7 +226,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="key"></param>
/// <returns></returns>
[PublicAPI]
public static bool TryGetKey<TKey, TValue>(this IDictionary<TKey, TValue> extends, TValue value, out TKey key)
public static bool TryGetKey<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends, TValue value,
out TKey key)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -235,7 +244,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="value"></param>
/// <returns></returns>
[PublicAPI]
public static IEnumerable<TKey> GetKeys<TKey, TValue>(this IDictionary<TKey, TValue> extends, TValue value)
public static IEnumerable<TKey> GetKeys<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends,
TValue value)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -253,8 +263,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="other"></param>
/// <returns></returns>
[PublicAPI]
public static bool Update<TKey, TValue>(this IDictionary<TKey, TValue> extends,
IEnumerable<KeyValuePair<TKey, TValue>> other)
public static bool Update<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends,
[NotNull] IEnumerable<KeyValuePair<TKey, TValue>> other)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -275,9 +285,9 @@ namespace ICD.Common.Utils.Extensions
/// <param name="comparer"></param>
/// <returns></returns>
[PublicAPI]
public static bool Update<TKey, TValue>(this IDictionary<TKey, TValue> extends,
IEnumerable<KeyValuePair<TKey, TValue>> other,
IEqualityComparer<TValue> comparer)
public static bool Update<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends,
[NotNull] IEnumerable<KeyValuePair<TKey, TValue>> other,
[NotNull] IEqualityComparer<TValue> 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<TKey, TValue> pair in other)
@@ -308,7 +321,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="items"></param>
[PublicAPI]
public static void AddRange<TKey, TValue>(this IDictionary<TKey, TValue> extends, IEnumerable<KeyValuePair<TKey, TValue>> items)
public static void AddRange<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends,
[NotNull] IEnumerable<KeyValuePair<TKey, TValue>> items)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -329,8 +343,9 @@ namespace ICD.Common.Utils.Extensions
/// <param name="items"></param>
/// <param name="getKey"></param>
[PublicAPI]
public static void AddRange<TKey, TValue>(this IDictionary<TKey, TValue> extends, IEnumerable<TValue> items,
Func<TValue, TKey> getKey)
public static void AddRange<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends,
[NotNull] IEnumerable<TValue> items,
[NotNull] Func<TValue, TKey> getKey)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -354,8 +369,9 @@ namespace ICD.Common.Utils.Extensions
/// <param name="items"></param>
/// <param name="getValue"></param>
[PublicAPI]
public static void AddRange<TKey, TValue>(this IDictionary<TKey, TValue> extends, IEnumerable<TKey> items,
Func<TKey, TValue> getValue)
public static void AddRange<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends,
[NotNull] IEnumerable<TKey> items,
[NotNull] Func<TKey, TValue> getValue)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -378,8 +394,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="items"></param>
[PublicAPI]
public static void AddRange<TKey, TValue>(this Dictionary<TKey, TValue> extends,
IEnumerable<KeyValuePair<TKey, TValue>> items)
public static void AddRange<TKey, TValue>([NotNull] this Dictionary<TKey, TValue> extends,
[NotNull] IEnumerable<KeyValuePair<TKey, TValue>> items)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -400,12 +416,15 @@ namespace ICD.Common.Utils.Extensions
/// <param name="other"></param>
/// <returns></returns>
[PublicAPI]
public static bool DictionaryEqual<TKey, TValue>(this IDictionary<TKey, TValue> extends,
IDictionary<TKey, TValue> other)
public static bool DictionaryEqual<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends,
[NotNull] IDictionary<TKey, TValue> other)
{
if (extends == null)
throw new ArgumentNullException("extends");
if (other == null)
throw new ArgumentNullException("other");
return extends.DictionaryEqual(other, EqualityComparer<TValue>.Default);
}
@@ -419,13 +438,16 @@ namespace ICD.Common.Utils.Extensions
/// <param name="valueComparer"></param>
/// <returns></returns>
[PublicAPI]
public static bool DictionaryEqual<TKey, TValue>(this IDictionary<TKey, TValue> extends,
IDictionary<TKey, TValue> other,
IEqualityComparer<TValue> valueComparer)
public static bool DictionaryEqual<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends,
[NotNull] IDictionary<TKey, TValue> other,
[NotNull] IEqualityComparer<TValue> 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
/// <param name="valueComparer"></param>
/// <returns></returns>
[PublicAPI]
public static bool DictionaryEqual<TKey, TValue>(this IDictionary<TKey, TValue> extends,
IDictionary<TKey, TValue> other,
Func<TValue, TValue, bool> valueComparer)
public static bool DictionaryEqual<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends,
[NotNull] IDictionary<TKey, TValue> other,
[NotNull] Func<TValue, TValue, bool> 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
/// <returns></returns>
[PublicAPI]
public static IEnumerable<KeyValuePair<TKey, TValue>> OrderByKey<TKey, TValue>(
this IEnumerable<KeyValuePair<TKey, TValue>> extends)
[NotNull] this IEnumerable<KeyValuePair<TKey, TValue>> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -495,7 +519,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static IEnumerable<TValue> OrderValuesByKey<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> extends)
public static IEnumerable<TValue> OrderValuesByKey<TKey, TValue>(
[NotNull] this IEnumerable<KeyValuePair<TKey, TValue>> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -511,7 +536,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static Dictionary<TValue, List<TKey>> ToInverse<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> extends)
public static Dictionary<TValue, List<TKey>> ToInverse<TKey, TValue>(
[NotNull] this IEnumerable<KeyValuePair<TKey, TValue>> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -532,5 +558,22 @@ namespace ICD.Common.Utils.Extensions
return output;
}
/// <summary>
/// Turns an enumerable of KeyValuePairs back into a dictionary
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(
[NotNull] this IEnumerable<KeyValuePair<TKey, TValue>> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
return extends.ToDictionary(x => x.Key, x => x.Value);
}
}
}

View File

@@ -17,7 +17,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="defaultItem"></param>
/// <returns></returns>
public static T FirstOrDefault<T>(this IEnumerable<T> extends, T defaultItem)
public static T FirstOrDefault<T>([NotNull] this IEnumerable<T> extends, T defaultItem)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -34,7 +34,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="predicate"></param>
/// <param name="defaultItem"></param>
/// <returns></returns>
public static T FirstOrDefault<T>(this IEnumerable<T> extends, Func<T, bool> predicate, T defaultItem)
public static T FirstOrDefault<T>([NotNull] this IEnumerable<T> extends, [NotNull] Func<T, bool> predicate,
T defaultItem)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -53,7 +54,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="item">Outputs the first item in the sequence.</param>
/// <returns></returns>
public static bool TryFirst<T>(this IEnumerable<T> extends, out T item)
public static bool TryFirst<T>([NotNull] this IEnumerable<T> extends, out T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -80,7 +81,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="predicate"></param>
/// <param name="item">Outputs the first item in the sequence.</param>
/// <returns></returns>
public static bool TryFirst<T>(this IEnumerable<T> extends, Func<T, bool> predicate, out T item)
public static bool TryFirst<T>([NotNull] this IEnumerable<T> extends, [NotNull] Func<T, bool> predicate,
out T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -112,7 +114,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="item">Outputs the last item in the sequence.</param>
/// <returns></returns>
public static bool TryLast<T>(this IEnumerable<T> extends, out T item)
public static bool TryLast<T>([NotNull] this IEnumerable<T> extends, out T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -139,7 +141,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="predicate"></param>
/// <param name="item">Outputs the last item in the sequence.</param>
/// <returns></returns>
public static bool TryLast<T>(this IEnumerable<T> extends, Func<T, bool> predicate, out T item)
public static bool TryLast<T>([NotNull] this IEnumerable<T> extends, [NotNull] Func<T, bool> predicate,
out T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -173,7 +176,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="index"></param>
/// <param name="item"></param>
/// <returns></returns>
public static bool TryElementAt<T>(this IEnumerable<T> extends, int index, out T item)
public static bool TryElementAt<T>([NotNull] this IEnumerable<T> 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
/// <param name="index"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static T ElementAtOrDefault<T>(this IEnumerable<T> extends, int index, T defaultValue)
public static T ElementAtOrDefault<T>([NotNull] this IEnumerable<T> extends, int index, T defaultValue)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -231,7 +235,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="other"></param>
/// <param name="comparer"></param>
/// <returns></returns>
public static bool SequenceEqual<T>(this IEnumerable<T> extends, IEnumerable<T> other, IEqualityComparer<T> comparer)
public static bool SequenceEqual<T>([NotNull] this IEnumerable<T> extends, [NotNull] IEnumerable<T> other,
[NotNull] IEqualityComparer<T> comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -253,7 +258,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="other"></param>
/// <param name="comparer"></param>
/// <returns></returns>
public static bool SequenceEqual<T>(this IEnumerable<T> extends, IEnumerable<T> other, Func<T, T, bool> comparer)
public static bool SequenceEqual<T>([NotNull] this IEnumerable<T> extends, [NotNull] IEnumerable<T> other,
[NotNull] Func<T, T, bool> comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -298,7 +304,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="other"></param>
/// <returns></returns>
public static bool ScrambledEquals<T>(this IEnumerable<T> extends, IEnumerable<T> other)
public static bool ScrambledEquals<T>([NotNull] this IEnumerable<T> extends, [NotNull] IEnumerable<T> other)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -317,7 +323,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="other"></param>
/// <param name="comparer"></param>
/// <returns></returns>
public static bool ScrambledEquals<T>(this IEnumerable<T> extends, IEnumerable<T> other, IEqualityComparer<T> comparer)
public static bool ScrambledEquals<T>([NotNull] this IEnumerable<T> extends, [NotNull] IEnumerable<T> other,
[NotNull] IEqualityComparer<T> comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -352,7 +359,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="match"></param>
/// <returns></returns>
public static int FindIndex<T>(this IEnumerable<T> extends, Predicate<T> match)
public static int FindIndex<T>([NotNull] this IEnumerable<T> extends, [NotNull] Predicate<T> match)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -370,7 +377,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="match"></param>
/// <returns></returns>
public static IEnumerable<int> FindIndices<T>(this IEnumerable<T> extends, Predicate<T> match)
public static IEnumerable<int> FindIndices<T>([NotNull] this IEnumerable<T> extends,
[NotNull] Predicate<T> match)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -388,7 +396,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="sequence"></param>
/// <param name="match"></param>
/// <returns></returns>
private static IEnumerable<int> FindIndicesIterator<T>(IEnumerable<T> sequence, Predicate<T> match)
private static IEnumerable<int> FindIndicesIterator<T>([NotNull] IEnumerable<T> sequence,
[NotNull] Predicate<T> match)
{
int index = 0;
@@ -408,7 +417,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="selectors"></param>
/// <returns></returns>
public static IEnumerable<TResult> SelectMulti<TSource, TResult>(this IEnumerable<TSource> extends,
public static IEnumerable<TResult> SelectMulti<TSource, TResult>([NotNull] this IEnumerable<TSource> extends,
[NotNull]
params Func<TSource, TResult>[] selectors)
{
if (extends == null)
@@ -427,7 +437,7 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
[PublicAPI]
public static void Execute<T>(this IEnumerable<T> extends)
public static void Execute<T>([NotNull] this IEnumerable<T> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -446,7 +456,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="action"></param>
[PublicAPI]
public static void ForEach<T>(this IEnumerable<T> extends, Action<T> action)
public static void ForEach<T>([NotNull] this IEnumerable<T> extends, [NotNull] Action<T> action)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -464,7 +474,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="action"></param>
[PublicAPI]
public static void ForEach<T>(this IEnumerable<T> extends, Action<T, int> action)
public static void ForEach<T>([NotNull] this IEnumerable<T> extends, [NotNull] Action<T, int> action)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -485,7 +495,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="item"></param>
/// <returns></returns>
public static IEnumerable<T> Prepend<T>(this IEnumerable<T> extends, T item)
public static IEnumerable<T> Prepend<T>([NotNull]this IEnumerable<T> extends, T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -500,7 +510,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="sequence"></param>
/// <param name="item"></param>
/// <returns></returns>
private static IEnumerable<T> PrependIterator<T>(IEnumerable<T> sequence, T item)
private static IEnumerable<T> PrependIterator<T>([NotNull]IEnumerable<T> sequence, T item)
{
yield return item;
@@ -517,7 +527,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="items"></param>
/// <returns></returns>
[PublicAPI]
public static IEnumerable<T> PrependMany<T>(this IEnumerable<T> extends, params T[] items)
public static IEnumerable<T> PrependMany<T>([NotNull] this IEnumerable<T> extends, [NotNull] params T[] items)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -535,7 +545,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="sequence"></param>
/// <param name="items"></param>
/// <returns></returns>
private static IEnumerable<T> PrependManyIterator<T>(IEnumerable<T> sequence, params T[] items)
private static IEnumerable<T> PrependManyIterator<T>([NotNull] IEnumerable<T> sequence,
[NotNull] params T[] items)
{
foreach (T item in items)
yield return item;
@@ -552,7 +563,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="item"></param>
/// <returns></returns>
public static IEnumerable<T> Append<T>(this IEnumerable<T> extends, T item)
public static IEnumerable<T> Append<T>([NotNull]this IEnumerable<T> extends, T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -567,7 +578,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="sequence"></param>
/// <param name="item"></param>
/// <returns></returns>
private static IEnumerable<T> AppendIterator<T>(IEnumerable<T> sequence, T item)
private static IEnumerable<T> AppendIterator<T>([NotNull]IEnumerable<T> sequence, T item)
{
foreach (T first in sequence)
yield return first;
@@ -584,7 +595,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="items"></param>
/// <returns></returns>
[PublicAPI]
public static IEnumerable<T> AppendMany<T>(this IEnumerable<T> extends, params T[] items)
public static IEnumerable<T> AppendMany<T>([NotNull] this IEnumerable<T> extends, [NotNull] params T[] items)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -602,7 +613,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="sequence"></param>
/// <param name="items"></param>
/// <returns></returns>
private static IEnumerable<T> AppendManyIterator<T>(IEnumerable<T> sequence, params T[] items)
private static IEnumerable<T> AppendManyIterator<T>([NotNull] IEnumerable<T> sequence,
[NotNull] params T[] items)
{
foreach (T each in sequence)
yield return each;
@@ -619,7 +631,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="count"></param>
/// <returns></returns>
[PublicAPI]
public static IEnumerable<T> PadRight<T>(this IEnumerable<T> extends, int count)
public static IEnumerable<T> PadRight<T>([NotNull] this IEnumerable<T> extends, int count)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -634,7 +646,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="sequence"></param>
/// <param name="count"></param>
/// <returns></returns>
private static IEnumerable<T> PadRightIterator<T>(IEnumerable<T> sequence, int count)
private static IEnumerable<T> PadRightIterator<T>([NotNull] IEnumerable<T> sequence, int count)
{
int index = 0;
@@ -654,7 +666,7 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <returns></returns>
public static bool AreOrdered<T>(this IEnumerable<T> extends)
public static bool AreOrdered<T>([NotNull] this IEnumerable<T> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -669,7 +681,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="comparer"></param>
/// <returns></returns>
public static bool AreOrdered<T>(this IEnumerable<T> extends, IComparer<T> comparer)
public static bool AreOrdered<T>([NotNull] this IEnumerable<T> extends, [NotNull] IComparer<T> comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -698,7 +710,7 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <returns></returns>
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> extends)
public static IOrderedEnumerable<T> Order<T>([NotNull] this IEnumerable<T> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -713,7 +725,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="comparer"></param>
/// <returns></returns>
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> extends, IComparer<T> comparer)
public static IOrderedEnumerable<T> Order<T>([NotNull] this IEnumerable<T> extends,
[NotNull] IComparer<T> comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -731,7 +744,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="comparer"></param>
/// <returns></returns>
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> extends, IComparer<T> comparer)
public static IOrderedEnumerable<T> OrderDescending<T>([NotNull] this IEnumerable<T> extends,
[NotNull] IComparer<T> comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -749,7 +763,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="item"></param>
/// <returns></returns>
public static IEnumerable<T> Except<T>(this IEnumerable<T> extends, T item)
public static IEnumerable<T> Except<T>([NotNull] this IEnumerable<T> extends, T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -765,7 +779,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="item"></param>
/// <param name="comparer"></param>
/// <returns></returns>
public static IEnumerable<T> Except<T>(this IEnumerable<T> extends, T item, IEqualityComparer<T> comparer)
public static IEnumerable<T> Except<T>([NotNull] this IEnumerable<T> extends, T item,
[NotNull] IEqualityComparer<T> comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -783,7 +798,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static IEnumerable<T> ExceptNulls<T>(this IEnumerable<T?> extends)
public static IEnumerable<T> ExceptNulls<T>([NotNull] this IEnumerable<T?> extends)
where T : struct
{
if (extends == null)
@@ -800,7 +815,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="array"></param>
/// <param name="index"></param>
public static void CopyTo<T>(this IEnumerable<T> extends, T[] array, int index)
public static void CopyTo<T>([NotNull] this IEnumerable<T> extends, [NotNull] T[] array, int index)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -829,7 +844,7 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <returns></returns>
public static IcdHashSet<T> ToIcdHashSet<T>(this IEnumerable<T> extends)
public static IcdHashSet<T> ToIcdHashSet<T>([NotNull] this IEnumerable<T> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -844,7 +859,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="comparer"></param>
/// <returns></returns>
public static IcdHashSet<T> ToIcdHashSet<T>(this IEnumerable<T> extends, IEqualityComparer<T> comparer)
public static IcdHashSet<T> ToIcdHashSet<T>([NotNull] this IEnumerable<T> extends,
[NotNull] IEqualityComparer<T> comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -862,7 +878,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="count"></param>
/// <returns></returns>
public static T[] ToArray<T>(this IEnumerable<T> extends, int count)
public static T[] ToArray<T>([NotNull] this IEnumerable<T> extends, int count)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -903,7 +919,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="count"></param>
/// <returns></returns>
public static List<T> ToList<T>(this IEnumerable<T> extends, int count)
public static List<T> ToList<T>([NotNull] this IEnumerable<T> extends, int count)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -923,7 +939,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static Dictionary<int, T> ToIndexedDictionary<T>(this IEnumerable<T> extends)
public static Dictionary<int, T> ToIndexedDictionary<T>([NotNull] this IEnumerable<T> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -940,7 +956,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static Dictionary<uint, T> ToIndexedDictionaryUInt<T>(this IEnumerable<T> extends)
public static Dictionary<uint, T> ToIndexedDictionaryUInt<T>([NotNull] this IEnumerable<T> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -950,22 +966,6 @@ namespace ICD.Common.Utils.Extensions
return output;
}
/// <summary>
/// Turns an enumerable of KeyValuePairs back into a dictionary
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
return extends.ToDictionary(x => x.Key, x => x.Value);
}
/// <summary>
/// Gets distinct elements from the sequence based on given property.
/// </summary>
@@ -975,8 +975,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="getProperty"></param>
/// <returns></returns>
[PublicAPI]
public static IEnumerable<TItem> Distinct<TItem, TProperty>(this IEnumerable<TItem> extends,
Func<TItem, TProperty> getProperty)
public static IEnumerable<TItem> Distinct<TItem, TProperty>([NotNull] this IEnumerable<TItem> extends,
[NotNull] Func<TItem, TProperty> getProperty)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -998,8 +998,9 @@ namespace ICD.Common.Utils.Extensions
/// <param name="propertyComparer"></param>
/// <returns></returns>
[PublicAPI]
public static IEnumerable<TItem> Distinct<TItem, TProperty>(this IEnumerable<TItem> extends,
public static IEnumerable<TItem> Distinct<TItem, TProperty>([NotNull] this IEnumerable<TItem> extends,
Func<TItem, TProperty> getProperty,
[NotNull]
IEqualityComparer<TProperty> propertyComparer)
{
if (extends == null)
@@ -1020,7 +1021,7 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <returns></returns>
public static T Random<T>(this IEnumerable<T> extends)
public static T Random<T>([NotNull] this IEnumerable<T> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -1045,7 +1046,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="other"></param>
/// <returns></returns>
[PublicAPI]
public static T Unanimous<T>(this IEnumerable<T> extends, T other)
public static T Unanimous<T>([NotNull] this IEnumerable<T> extends, T other)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -1063,7 +1064,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="result"></param>
/// <returns></returns>
[PublicAPI]
public static bool Unanimous<T>(this IEnumerable<T> extends, out T result)
public static bool Unanimous<T>([NotNull] this IEnumerable<T> extends, out T result)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -1081,7 +1082,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="result"></param>
/// <returns></returns>
[PublicAPI]
public static bool Unanimous<T>(this IEnumerable<T> extends, IEqualityComparer<T> comparer, out T result)
public static bool Unanimous<T>([NotNull] this IEnumerable<T> extends, [NotNull] IEqualityComparer<T> comparer,
out T result)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -1120,7 +1122,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="partitionSize"></param>
/// <returns></returns>
[PublicAPI]
public static IEnumerable<IEnumerable<T>> Partition<T>(this IEnumerable<T> extends, int partitionSize)
public static IEnumerable<IEnumerable<T>> Partition<T>([NotNull] this IEnumerable<T> extends, int partitionSize)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -1134,7 +1136,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="sequence"></param>
/// <param name="partitionSize"></param>
/// <returns></returns>
private static IEnumerable<IEnumerable<T>> PartitionIterator<T>(IEnumerable<T> sequence, int partitionSize)
private static IEnumerable<IEnumerable<T>> PartitionIterator<T>([NotNull] IEnumerable<T> sequence,
int partitionSize)
{
using (IEnumerator<T> enumerator = sequence.GetEnumerator())
{
@@ -1143,7 +1146,7 @@ namespace ICD.Common.Utils.Extensions
}
}
private static IEnumerable<T> YieldBatchElements<T>(IEnumerator<T> source, int partitionSize)
private static IEnumerable<T> YieldBatchElements<T>([NotNull] IEnumerator<T> source, int partitionSize)
{
if (source == null)
throw new ArgumentNullException("source");
@@ -1164,7 +1167,7 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="T">Type of the object.</typeparam>
/// <param name="item">The instance that will be wrapped.</param>
/// <returns>An IEnumerable&lt;T&gt; consisting of a single item.</returns>
public static IEnumerable<T> Yield<T>(this T item)
public static IEnumerable<T> Yield<T>([CanBeNull] this T item)
{
yield return item;
}
@@ -1175,7 +1178,7 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <returns></returns>
public static IEnumerable<T[]> GetAdjacentPairs<T>(this IEnumerable<T> extends)
public static IEnumerable<T[]> GetAdjacentPairs<T>([NotNull] this IEnumerable<T> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -1189,7 +1192,7 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <returns></returns>
private static IEnumerable<T[]> GetAdjacentPairsIterator<T>(IEnumerable<T> extends)
private static IEnumerable<T[]> GetAdjacentPairsIterator<T>([NotNull] IEnumerable<T> extends)
{
T previous = default(T);
bool first = true;
@@ -1197,7 +1200,7 @@ namespace ICD.Common.Utils.Extensions
foreach (T item in extends)
{
if (!first)
yield return new[] { previous, item };
yield return new[] {previous, item};
first = false;
previous = item;
@@ -1211,7 +1214,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="getDelta"></param>
/// <returns></returns>
public static T GetClosest<T>(this IEnumerable<T> extends, Func<T, int> getDelta)
public static T GetClosest<T>([NotNull] this IEnumerable<T> extends, [NotNull] Func<T, int> getDelta)
{
return extends.MinBy(n => Math.Abs(getDelta(n)));
}
@@ -1234,8 +1237,8 @@ namespace ICD.Common.Utils.Extensions
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null</exception>
/// <exception cref="InvalidOperationException"><paramref name="source"/> is empty</exception>
[PublicAPI]
public static TSource MinBy<TSource, TKey>(this IEnumerable<TSource> source,
Func<TSource, TKey> selector)
public static TSource MinBy<TSource, TKey>([NotNull] this IEnumerable<TSource> source,
[NotNull] Func<TSource, TKey> selector)
{
if (source == null)
throw new ArgumentNullException("source");
@@ -1265,8 +1268,9 @@ namespace ICD.Common.Utils.Extensions
/// or <paramref name="comparer"/> is null</exception>
/// <exception cref="InvalidOperationException"><paramref name="source"/> is empty</exception>
[PublicAPI]
public static TSource MinBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> selector,
IComparer<TKey> comparer)
public static TSource MinBy<TSource, TKey>([NotNull] this IEnumerable<TSource> source,
[NotNull] Func<TSource, TKey> selector,
[NotNull] IComparer<TKey> comparer)
{
if (source == null)
throw new ArgumentNullException("source");
@@ -1307,7 +1311,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static byte Sum(this IEnumerable<byte> extends)
public static byte Sum([NotNull] this IEnumerable<byte> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -1326,7 +1330,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static IEnumerable<T> Consolidate<T>(this IEnumerable<T> extends)
public static IEnumerable<T> Consolidate<T>([NotNull] this IEnumerable<T> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -1346,7 +1350,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="comparer"></param>
/// <returns></returns>
[PublicAPI]
public static IEnumerable<T> Consolidate<T>(this IEnumerable<T> extends, IComparer<T> comparer)
public static IEnumerable<T> Consolidate<T>([NotNull] this IEnumerable<T> extends,
[NotNull] IComparer<T> comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -1368,7 +1373,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="sequence"></param>
/// <param name="comparer"></param>
/// <returns></returns>
private static IEnumerable<T> ConsolidateIterator<T>(IEnumerable<T> sequence, IComparer<T> comparer)
private static IEnumerable<T> ConsolidateIterator<T>([NotNull] IEnumerable<T> sequence,
[NotNull] IComparer<T> comparer)
{
bool first = true;
T last = default(T);
@@ -1394,7 +1400,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="predicate"></param>
/// <returns></returns>
[PublicAPI]
public static bool AnyAndAll<T>(this IEnumerable<T> extends, Func<T, bool> predicate)
public static bool AnyAndAll<T>([NotNull] this IEnumerable<T> extends, [NotNull] Func<T, bool> predicate)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -1420,11 +1426,12 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="TSecond"></typeparam>
/// <param name="extends"></param>
/// <param name="second"></param>
public static IEnumerable<KeyValuePair<TFirst, TSecond>> Zip<TFirst, TSecond>(this IEnumerable<TFirst> extends,
IEnumerable<TSecond> second)
public static IEnumerable<KeyValuePair<TFirst, TSecond>> Zip<TFirst, TSecond>(
[NotNull] this IEnumerable<TFirst> extends,
[NotNull] IEnumerable<TSecond> second)
{
if (extends == null)
throw new ArgumentNullException("first");
throw new ArgumentNullException("extends");
if (second == null)
throw new ArgumentNullException("second");
@@ -1441,9 +1448,9 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="second"></param>
/// <param name="callback"></param>
public static void Zip<TFirst, TSecond>(this IEnumerable<TFirst> extends,
IEnumerable<TSecond> second,
Action<TFirst, TSecond> callback)
public static void Zip<TFirst, TSecond>([NotNull]this IEnumerable<TFirst> extends,
[NotNull]IEnumerable<TSecond> second,
[NotNull]Action<TFirst, TSecond> callback)
{
if (extends == null)
throw new ArgumentNullException("first");
@@ -1474,9 +1481,9 @@ namespace ICD.Common.Utils.Extensions
/// <param name="other"></param>
/// <param name="callback"></param>
/// <returns></returns>
public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(this IEnumerable<TFirst> extends,
IEnumerable<TSecond> other,
Func<TFirst, TSecond, TResult> callback)
public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>([NotNull]this IEnumerable<TFirst> extends,
[NotNull]IEnumerable<TSecond> other,
[NotNull]Func<TFirst, TSecond, TResult> callback)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -1500,9 +1507,9 @@ namespace ICD.Common.Utils.Extensions
/// <param name="second"></param>
/// <param name="callback"></param>
/// <returns></returns>
private static IEnumerable<TResult> ZipIterator<TFirst, TSecond, TResult>(IEnumerable<TFirst> first,
IEnumerable<TSecond> second,
Func<TFirst, TSecond, TResult> callback)
private static IEnumerable<TResult> ZipIterator<TFirst, TSecond, TResult>([NotNull]IEnumerable<TFirst> first,
[NotNull]IEnumerable<TSecond> second,
[NotNull]Func<TFirst, TSecond, TResult> callback)
{
using (IEnumerator<TFirst> enumerator1 = first.GetEnumerator())
{

View File

@@ -1,9 +1,5 @@
using System;
#if SIMPLSHARP
using Crestron.SimplSharp.Reflection;
#else
using System.Reflection;
#endif
using ICD.Common.Properties;
namespace ICD.Common.Utils.Extensions
{
@@ -17,7 +13,7 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <param name="sender"></param>
public static void Raise(this EventHandler extends, object sender)
public static void Raise([CanBeNull] this EventHandler extends, object sender)
{
if (extends != null)
extends(sender, EventArgs.Empty);
@@ -30,7 +26,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="sender"></param>
/// <param name="args"></param>
public static void Raise<T>(this EventHandler<T> extends, object sender, T args)
public static void Raise<T>([CanBeNull]this EventHandler<T> extends, object sender, [NotNull]T args)
where T : EventArgs
{
if (args == null)
@@ -39,22 +35,5 @@ namespace ICD.Common.Utils.Extensions
if (extends != null)
extends(sender, args);
}
/// <summary>
/// Cross-platform shim for getting MethodInfo for the delegate.
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static MethodInfo GetMethodInfo(this Delegate extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
#if SIMPLSHARP
return extends.GetMethod();
#else
return extends.Method;
#endif
}
}
}

View File

@@ -15,7 +15,7 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <returns></returns>
public static T ReadAsObject<T>(this JsonReader extends)
public static T ReadAsObject<T>([NotNull] this JsonReader extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -36,7 +36,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="serializer"></param>
/// <returns></returns>
public static T ReadAsObject<T>(this JsonReader extends, JsonSerializer serializer)
public static T ReadAsObject<T>([NotNull] this JsonReader extends, [NotNull] JsonSerializer serializer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -53,8 +53,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="serializer"></param>
/// <param name="readPropertyValue"></param>
public static void ReadObject(this JsonReader extends, JsonSerializer serializer,
Action<string, JsonReader, JsonSerializer> readPropertyValue)
public static void ReadObject([NotNull] this JsonReader extends, [NotNull] JsonSerializer serializer,
[NotNull] Action<string, JsonReader, JsonSerializer> readPropertyValue)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -69,7 +69,8 @@ namespace ICD.Common.Utils.Extensions
return;
if (extends.TokenType != JsonToken.StartObject)
throw new FormatException(string.Format("Expected {0} got {1}", JsonToken.StartObject, extends.TokenType));
throw new FormatException(string.Format("Expected {0} got {1}", JsonToken.StartObject,
extends.TokenType));
while (extends.Read())
{
@@ -94,7 +95,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static Type GetValueAsType(this JsonReader extends)
public static Type GetValueAsType([NotNull] this JsonReader extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -109,7 +110,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static uint GetValueAsUInt(this JsonReader extends)
public static uint GetValueAsUInt([NotNull] this JsonReader extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -117,7 +118,8 @@ namespace ICD.Common.Utils.Extensions
if (extends.TokenType == JsonToken.Integer)
return (uint)(long)extends.Value;
string message = string.Format("Token {0} {1} is not {2}", extends.TokenType, extends.Value, JsonToken.Integer);
string message = string.Format("Token {0} {1} is not {2}", extends.TokenType, extends.Value,
JsonToken.Integer);
throw new InvalidCastException(message);
}
@@ -127,7 +129,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static int GetValueAsInt(this JsonReader extends)
public static int GetValueAsInt([NotNull] this JsonReader extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -135,7 +137,8 @@ namespace ICD.Common.Utils.Extensions
if (extends.TokenType == JsonToken.Integer)
return (int)(long)extends.Value;
string message = string.Format("Token {0} {1} is not {2}", extends.TokenType, extends.Value, JsonToken.Integer);
string message = string.Format("Token {0} {1} is not {2}", extends.TokenType, extends.Value,
JsonToken.Integer);
throw new InvalidCastException(message);
}
@@ -145,7 +148,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static string GetValueAsString(this JsonReader extends)
public static string GetValueAsString([NotNull] this JsonReader extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -168,7 +171,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static bool GetValueAsBool(this JsonReader extends)
public static bool GetValueAsBool([NotNull] this JsonReader extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -176,7 +179,8 @@ namespace ICD.Common.Utils.Extensions
if (extends.TokenType == JsonToken.Boolean)
return (bool)extends.Value;
string message = string.Format("Token {0} {1} is not {2}", extends.TokenType, extends.Value, JsonToken.Boolean);
string message = string.Format("Token {0} {1} is not {2}", extends.TokenType, extends.Value,
JsonToken.Boolean);
throw new InvalidCastException(message);
}
@@ -186,7 +190,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static T GetValueAsEnum<T>(this JsonReader extends)
public static T GetValueAsEnum<T>([NotNull] this JsonReader extends)
where T : struct, IConvertible
{
if (extends == null)
@@ -204,7 +208,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static Guid GetValueAsGuid(this JsonReader extends)
public static Guid GetValueAsGuid([NotNull] this JsonReader extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -218,7 +222,7 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static DateTime GetValueAsDateTime(this JsonReader extends)
public static DateTime GetValueAsDateTime([NotNull] this JsonReader extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -240,11 +244,15 @@ namespace ICD.Common.Utils.Extensions
/// <param name="format"></param>
/// <param name="provider"></param>
/// <returns></returns>
public static DateTime GetValueAsDateTimeExact(this JsonReader extends, string format, IFormatProvider provider)
public static DateTime GetValueAsDateTimeExact([NotNull] this JsonReader extends, [NotNull] string format,
IFormatProvider provider)
{
if (extends == null)
throw new ArgumentNullException("extends");
if (format == null)
throw new ArgumentNullException("format");
#if !SIMPLSHARP
// Newer NewtonSoft tries to be helpful by assuming that anything that looks like a DateTime must be a date.
if (extends.DateParseHandling != DateParseHandling.None)

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ICD.Common.Properties;
using Newtonsoft.Json;
namespace ICD.Common.Utils.Extensions
@@ -16,8 +17,16 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="TItem"></typeparam>
/// <param name="extends"></param>
/// <param name="reader"></param>
public static IEnumerable<TItem> DeserializeArray<TItem>(this JsonSerializer extends, JsonReader reader)
[CanBeNull]
public static IEnumerable<TItem> DeserializeArray<TItem>([NotNull] this JsonSerializer extends,
[NotNull] JsonReader reader)
{
if (extends == null)
throw new ArgumentNullException("extends");
if (reader == null)
throw new ArgumentNullException("reader");
return extends.DeserializeArray(reader, (s, r) => extends.Deserialize<TItem>(reader));
}
@@ -28,8 +37,10 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="reader"></param>
/// <param name="read"></param>
public static IEnumerable<TItem> DeserializeArray<TItem>(this JsonSerializer extends, JsonReader reader,
Func<JsonSerializer, JsonReader, TItem> read)
[CanBeNull]
public static IEnumerable<TItem> DeserializeArray<TItem>([NotNull] this JsonSerializer extends,
[NotNull] JsonReader reader,
[NotNull] Func<JsonSerializer, JsonReader, TItem> read)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -41,10 +52,11 @@ namespace ICD.Common.Utils.Extensions
throw new ArgumentNullException("read");
if (reader.TokenType == JsonToken.Null)
return Enumerable.Empty<TItem>();
return null;
if (reader.TokenType != JsonToken.StartArray)
throw new FormatException(string.Format("Expected token {0} got {1}", JsonToken.StartArray, reader.TokenType));
throw new FormatException(string.Format("Expected token {0} got {1}", JsonToken.StartArray,
reader.TokenType));
// ToArray to ensure everything gets read before moving onto the next token
return DeserializeArrayIterator(extends, reader, read).ToArray();
@@ -57,8 +69,10 @@ namespace ICD.Common.Utils.Extensions
/// <param name="serializer"></param>
/// <param name="reader"></param>
/// <param name="read"></param>
private static IEnumerable<TItem> DeserializeArrayIterator<TItem>(JsonSerializer serializer, JsonReader reader,
Func<JsonSerializer, JsonReader, TItem> read)
[NotNull]
private static IEnumerable<TItem> DeserializeArrayIterator<TItem>(
[NotNull] JsonSerializer serializer, [NotNull] JsonReader reader,
[NotNull] Func<JsonSerializer, JsonReader, TItem> read)
{
// Step into the first value
reader.Read();
@@ -80,8 +94,10 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="TValue"></typeparam>
/// <param name="extends"></param>
/// <param name="reader"></param>
public static IEnumerable<KeyValuePair<TKey, TValue>> DeserializeDict<TKey, TValue>(this JsonSerializer extends,
JsonReader reader)
[CanBeNull]
public static IEnumerable<KeyValuePair<TKey, TValue>> DeserializeDict<TKey, TValue>(
[NotNull] this JsonSerializer extends,
[NotNull] JsonReader reader)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -103,12 +119,12 @@ namespace ICD.Common.Utils.Extensions
/// <param name="reader"></param>
/// <param name="readKey"></param>
/// <param name="readValue"></param>
public static IEnumerable<KeyValuePair<TKey, TValue>> DeserializeDict<TKey, TValue>(this JsonSerializer extends,
JsonReader reader,
Func<JsonSerializer, JsonReader,
TKey> readKey,
Func<JsonSerializer, JsonReader,
TValue> readValue)
[CanBeNull]
public static IEnumerable<KeyValuePair<TKey, TValue>> DeserializeDict<TKey, TValue>(
[NotNull] this JsonSerializer extends,
[NotNull] JsonReader reader,
[NotNull] Func<JsonSerializer, JsonReader, TKey> readKey,
[NotNull] Func<JsonSerializer, JsonReader, TValue> readValue)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -125,11 +141,11 @@ namespace ICD.Common.Utils.Extensions
return extends.DeserializeArray(reader, (s, r) => s.DeserializeKeyValuePair(r, readKey, readValue));
}
public static KeyValuePair<TKey, TValue> DeserializeKeyValuePair<TKey, TValue>(this JsonSerializer extends, JsonReader reader,
Func<JsonSerializer, JsonReader,
TKey> readKey,
Func<JsonSerializer, JsonReader,
TValue> readValue)
public static KeyValuePair<TKey, TValue> DeserializeKeyValuePair<TKey, TValue>(
[NotNull] this JsonSerializer extends,
[NotNull] JsonReader reader,
[NotNull] Func<JsonSerializer, JsonReader, TKey> readKey,
[NotNull] Func<JsonSerializer, JsonReader, TValue> readValue)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -144,7 +160,8 @@ namespace ICD.Common.Utils.Extensions
throw new ArgumentNullException("readValue");
if (reader.TokenType != JsonToken.StartObject)
throw new FormatException(string.Format("Expected token {0} got {1}", JsonToken.StartObject, reader.TokenType));
throw new FormatException(string.Format("Expected token {0} got {1}", JsonToken.StartObject,
reader.TokenType));
TKey key = default(TKey);
TValue value = default(TValue);
@@ -155,7 +172,8 @@ namespace ICD.Common.Utils.Extensions
while (reader.TokenType != JsonToken.EndObject)
{
if (reader.TokenType != JsonToken.PropertyName)
throw new FormatException(string.Format("Expected token {0} got {1}", JsonToken.PropertyName, reader.TokenType));
throw new FormatException(string.Format("Expected token {0} got {1}", JsonToken.PropertyName,
reader.TokenType));
string propertyName = (string)reader.Value;
@@ -190,8 +208,15 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="writer"></param>
/// <param name="items"></param>
public static void SerializeArray<TItem>(this JsonSerializer extends, JsonWriter writer, IEnumerable<TItem> items)
public static void SerializeArray<TItem>([NotNull] this JsonSerializer extends, [NotNull] JsonWriter writer,
[CanBeNull] IEnumerable<TItem> items)
{
if (extends == null)
throw new ArgumentNullException("extends");
if (writer == null)
throw new ArgumentNullException("writer");
extends.SerializeArray(writer, items, (s, w, item) => s.Serialize(w, item));
}
@@ -203,8 +228,9 @@ namespace ICD.Common.Utils.Extensions
/// <param name="writer"></param>
/// <param name="items"></param>
/// <param name="write"></param>
public static void SerializeArray<TItem>(this JsonSerializer extends, JsonWriter writer, IEnumerable<TItem> items,
Action<JsonSerializer, JsonWriter, TItem> write)
public static void SerializeArray<TItem>([NotNull] this JsonSerializer extends, [NotNull] JsonWriter writer,
[CanBeNull] IEnumerable<TItem> items,
[NotNull] Action<JsonSerializer, JsonWriter, TItem> write)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -237,8 +263,9 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="writer"></param>
/// <param name="items"></param>
public static void SerializeDict<TKey, TValue>(this JsonSerializer extends, JsonWriter writer,
IEnumerable<KeyValuePair<TKey, TValue>> items)
public static void SerializeDict<TKey, TValue>([NotNull] this JsonSerializer extends,
[NotNull] JsonWriter writer,
[CanBeNull] IEnumerable<KeyValuePair<TKey, TValue>> items)
{
extends.SerializeDict(writer, items,
(s, w, k) => s.Serialize(w, k),
@@ -255,10 +282,11 @@ namespace ICD.Common.Utils.Extensions
/// <param name="items"></param>
/// <param name="writeKey"></param>
/// <param name="writeValue"></param>
public static void SerializeDict<TKey, TValue>(this JsonSerializer extends, JsonWriter writer,
IEnumerable<KeyValuePair<TKey, TValue>> items,
Action<JsonSerializer, JsonWriter, TKey> writeKey,
Action<JsonSerializer, JsonWriter, TValue> writeValue)
public static void SerializeDict<TKey, TValue>([NotNull] this JsonSerializer extends,
[NotNull] JsonWriter writer,
[CanBeNull] IEnumerable<KeyValuePair<TKey, TValue>> items,
[NotNull] Action<JsonSerializer, JsonWriter, TKey> writeKey,
[NotNull] Action<JsonSerializer, JsonWriter, TValue> writeValue)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -275,10 +303,11 @@ namespace ICD.Common.Utils.Extensions
extends.SerializeArray(writer, items, (s, w, kvp) => s.SerializeKeyValuePair(w, kvp, writeKey, writeValue));
}
public static void SerializeKeyValuePair<TKey, TValue>(this JsonSerializer extends, JsonWriter writer,
KeyValuePair<TKey, TValue> kvp,
Action<JsonSerializer, JsonWriter, TKey> writeKey,
Action<JsonSerializer, JsonWriter, TValue> writeValue)
public static void SerializeKeyValuePair<TKey, TValue>(
[NotNull] this JsonSerializer extends,
[NotNull] JsonWriter writer, KeyValuePair<TKey, TValue> kvp,
[NotNull] Action<JsonSerializer, JsonWriter, TKey> writeKey,
[NotNull] Action<JsonSerializer, JsonWriter, TValue> writeValue)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -303,4 +332,4 @@ namespace ICD.Common.Utils.Extensions
writer.WriteEndObject();
}
}
}
}

View File

@@ -12,7 +12,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="type"></param>
[PublicAPI]
public static void WriteType(this JsonWriter extends, Type type)
public static void WriteType([NotNull]this JsonWriter extends, [CanBeNull]Type type)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -33,7 +33,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="propertyName"></param>
/// <param name="value"></param>
public static void WriteProperty(this JsonWriter extends, string propertyName, object value)
public static void WriteProperty([NotNull]this JsonWriter extends, string propertyName, object value)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -48,7 +48,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="propertyName"></param>
/// <param name="value"></param>
public static void WriteProperty(this JsonWriter extends, string propertyName, string value)
public static void WriteProperty([NotNull]this JsonWriter extends, string propertyName, string value)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -63,7 +63,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="propertyName"></param>
/// <param name="value"></param>
public static void WriteProperty(this JsonWriter extends, string propertyName, DateTime value)
public static void WriteProperty([NotNull]this JsonWriter extends, string propertyName, DateTime value)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -78,7 +78,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="propertyName"></param>
/// <param name="value"></param>
public static void WriteProperty(this JsonWriter extends, string propertyName, bool value)
public static void WriteProperty([NotNull]this JsonWriter extends, string propertyName, bool value)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -93,7 +93,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="propertyName"></param>
/// <param name="value"></param>
public static void WriteProperty(this JsonWriter extends, string propertyName, int value)
public static void WriteProperty([NotNull]this JsonWriter extends, string propertyName, int value)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -108,7 +108,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="propertyName"></param>
/// <param name="value"></param>
public static void WriteProperty(this JsonWriter extends, string propertyName, Guid value)
public static void WriteProperty([NotNull]this JsonWriter extends, string propertyName, Guid value)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -123,7 +123,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="propertyName"></param>
/// <param name="value"></param>
public static void WriteProperty(this JsonWriter extends, string propertyName, Type value)
public static void WriteProperty([NotNull]this JsonWriter extends, string propertyName, Type value)
{
if (extends == null)
throw new ArgumentNullException("extends");

View File

@@ -21,7 +21,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="item"></param>
/// <returns></returns>
[PublicAPI]
public static bool AddSorted<T>(this IList<T> extends, T item)
public static bool AddSorted<T>([NotNull] this IList<T> extends, T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -39,7 +39,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="item"></param>
/// <param name="predicate"></param>
[PublicAPI]
public static bool AddSorted<T, TProp>(this IList<T> extends, T item, Func<T, TProp> predicate)
public static bool AddSorted<T, TProp>([NotNull] this IList<T> extends, T item,
[NotNull] Func<T, TProp> predicate)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -61,7 +62,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="comparer"></param>
/// <returns></returns>
[PublicAPI]
public static bool AddSorted<T>(this IList<T> extends, T item, IComparer<T> comparer)
public static bool AddSorted<T>([NotNull] this IList<T> extends, T item, [NotNull] IComparer<T> comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -92,7 +93,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="item"></param>
/// <returns></returns>
[PublicAPI]
public static bool RemoveSorted<T>(this IList<T> extends, T item)
public static bool RemoveSorted<T>([NotNull] this IList<T> extends, T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -110,7 +111,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="item"></param>
/// <param name="predicate"></param>
[PublicAPI]
public static bool RemoveSorted<T, TProp>(this IList<T> extends, T item, Func<T, TProp> predicate)
public static bool RemoveSorted<T, TProp>([NotNull] this IList<T> extends, T item,
[NotNull] Func<T, TProp> predicate)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -132,7 +134,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="comparer"></param>
/// <returns></returns>
[PublicAPI]
public static bool RemoveSorted<T>(this IList<T> extends, T item, IComparer<T> comparer)
public static bool RemoveSorted<T>([NotNull] this IList<T> extends, T item, [NotNull] IComparer<T> comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -160,7 +162,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="items"></param>
[PublicAPI]
public static void InsertSorted<T>(this IList<T> extends, IEnumerable<T> items)
public static void InsertSorted<T>([NotNull] this IList<T> extends, [NotNull] IEnumerable<T> items)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -179,7 +181,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="items"></param>
/// <param name="comparer"></param>
[PublicAPI]
public static void InsertSorted<T>(this IList<T> extends, IEnumerable<T> items, IComparer<T> comparer)
public static void InsertSorted<T>([NotNull] this IList<T> extends, [NotNull] IEnumerable<T> items,
[NotNull] IComparer<T> comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -202,7 +205,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="items"></param>
/// <param name="predicate"></param>
[PublicAPI]
public static void InsertSorted<T, TProp>(this IList<T> extends, IEnumerable<T> items, Func<T, TProp> predicate)
public static void InsertSorted<T, TProp>([NotNull] this IList<T> extends, [NotNull] IEnumerable<T> items,
[NotNull] Func<T, TProp> predicate)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -224,7 +228,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="item"></param>
[PublicAPI]
public static int InsertSorted<T>(this IList<T> extends, T item)
public static int InsertSorted<T>([NotNull] this IList<T> extends, T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -241,7 +245,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="item"></param>
/// <param name="predicate"></param>
[PublicAPI]
public static int InsertSorted<T, TProp>(this IList<T> extends, T item, Func<T, TProp> predicate)
public static int InsertSorted<T, TProp>([NotNull] this IList<T> extends, T item,
[NotNull] Func<T, TProp> predicate)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -261,7 +266,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="item"></param>
/// <param name="comparer"></param>
[PublicAPI]
public static int InsertSorted<T>(this IList<T> extends, T item, IComparer<T> comparer)
public static int InsertSorted<T>([NotNull] this IList<T> extends, T item, [NotNull] IComparer<T> comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -281,7 +286,7 @@ namespace ICD.Common.Utils.Extensions
#endregion
#region Contains Sorted
/// <summary>
/// Returns true if the sorted list contains the given item.
/// </summary>
@@ -290,7 +295,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="item"></param>
/// <returns></returns>
[PublicAPI]
public static bool ContainsSorted<T>(this IList<T> extends, T item)
public static bool ContainsSorted<T>([NotNull] this IList<T> extends, T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -307,7 +312,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="comparer"></param>
/// <returns></returns>
[PublicAPI]
public static bool ContainsSorted<T>(this IList<T> extends, T item, IComparer<T> comparer)
public static bool ContainsSorted<T>([NotNull] this IList<T> extends, T item, [NotNull] IComparer<T> comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -331,7 +336,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="comparer"></param>
/// <returns></returns>
[PublicAPI]
public static int BinarySearch<T>(this IList<T> extends, T item, IComparer<T> comparer)
public static int BinarySearch<T>([NotNull] this IList<T> extends, T item, [NotNull] IComparer<T> comparer)
{
if (extends == null)
throw new ArgumentNullException("extends");

View File

@@ -1,5 +1,6 @@
using System;
using System.Text;
using ICD.Common.Properties;
#if SIMPLSHARP
using Crestron.SimplSharp.Reflection;
#else
@@ -15,8 +16,11 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="method">The Method</param>
/// <returns>Method signature</returns>
public static string GetSignature(this MethodInfo method)
public static string GetSignature([NotNull]this MethodInfo method)
{
if (method == null)
throw new ArgumentNullException("method");
return method.GetSignature(false);
}
@@ -26,8 +30,11 @@ namespace ICD.Common.Utils.Extensions
/// <param name="method">The Method</param>
/// <param name="callable">Return as a callable string(public void a(string b) would return a(b))</param>
/// <returns>Method signature</returns>
public static string GetSignature(this MethodInfo method, bool callable)
public static string GetSignature([NotNull]this MethodInfo method, bool callable)
{
if (method == null)
throw new ArgumentNullException("method");
bool firstParam = true;
StringBuilder sigBuilder = new StringBuilder();
@@ -123,5 +130,22 @@ namespace ICD.Common.Utils.Extensions
return sigBuilder.ToString();
}
/// <summary>
/// Cross-platform shim for getting MethodInfo for the delegate.
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static MethodInfo GetMethodInfo([NotNull]this Delegate extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
#if SIMPLSHARP
return extends.GetMethod();
#else
return extends.Method;
#endif
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using ICD.Common.Properties;
#if SIMPLSHARP
using Crestron.SimplSharp.Reflection;
#else
@@ -14,7 +15,7 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static bool GetIsOut(this ParameterInfo extends)
public static bool GetIsOut([NotNull] this ParameterInfo extends)
{
if (extends == null)
throw new ArgumentNullException("extends");

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using ICD.Common.Properties;
namespace ICD.Common.Utils.Extensions
{
@@ -11,7 +12,7 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <param name="items"></param>
public static void EnqueueRange<T>(this Queue<T> extends, IEnumerable<T> items)
public static void EnqueueRange<T>([NotNull] this Queue<T> extends, [NotNull] IEnumerable<T> items)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -30,7 +31,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="item"></param>
/// <returns></returns>
public static bool Dequeue<T>(this Queue<T> extends, out T item)
public static bool Dequeue<T>([NotNull] this Queue<T> extends, out T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -51,7 +52,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="item"></param>
/// <returns></returns>
public static bool Peek<T>(this Queue<T> extends, out T item)
public static bool Peek<T>([NotNull] this Queue<T> extends, out T item)
{
if (extends == null)
throw new ArgumentNullException("extends");

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ICD.Common.Properties;
#if SIMPLSHARP
using Crestron.SimplSharp.Reflection;
#else
@@ -20,7 +21,7 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <returns></returns>
public static IEnumerable<T> GetCustomAttributes<T>(this ICustomAttributeProvider extends)
public static IEnumerable<T> GetCustomAttributes<T>([NotNull] this ICustomAttributeProvider extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -35,7 +36,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="inherits"></param>
/// <returns></returns>
public static IEnumerable<T> GetCustomAttributes<T>(this ICustomAttributeProvider extends, bool inherits)
public static IEnumerable<T> GetCustomAttributes<T>([NotNull] this ICustomAttributeProvider extends,
bool inherits)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -57,7 +59,7 @@ namespace ICD.Common.Utils.Extensions
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <returns></returns>
public static T GetCustomAttribute<T>(this ICustomAttributeProvider extends)
public static T GetCustomAttribute<T>([NotNull] this ICustomAttributeProvider extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -72,7 +74,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="inherits"></param>
/// <returns></returns>
public static T GetCustomAttribute<T>(this ICustomAttributeProvider extends, bool inherits)
public static T GetCustomAttribute<T>([NotNull] this ICustomAttributeProvider extends, bool inherits)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -86,16 +88,18 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <param name="inherits"></param>
/// <returns></returns>
public static IEnumerable<T> GetCustomAttributesIncludingBaseInterfaces<T>(this Type extends)
public static IEnumerable<T> GetCustomAttributesIncludingBaseInterfaces<T>([NotNull] this Type extends)
where T : Attribute
{
if (extends == null)
throw new ArgumentNullException("extends");
return extends.GetCustomAttributes<T>(true)
.Union(extends.GetInterfaces()
.SelectMany(interfaceType => interfaceType
.GetCustomAttributes<T>(true)))
.Distinct();
.Union(extends.GetInterfaces()
.SelectMany(interfaceType => interfaceType
.GetCustomAttributes<T>(true)))
.Distinct();
}
/// <summary>
@@ -103,23 +107,25 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <param name="inherits"></param>
/// <returns></returns>
public static IEnumerable<T> GetCustomAttributesIncludingBaseInterfaces<T>(this MemberInfo extends)
public static IEnumerable<T> GetCustomAttributesIncludingBaseInterfaces<T>([NotNull] this MemberInfo extends)
where T : Attribute
{
if (extends == null)
throw new ArgumentNullException("extends");
return extends.GetCustomAttributes<T>(true)
.Union(extends.DeclaringType?
.GetInterfaces()
.SelectMany(interfaceType => interfaceType
.GetMember(
extends.Name,
extends.MemberType,
BindingFlags.Instance)
.FirstOrDefault()?
.GetCustomAttributes<T>(true) ?? Enumerable.Empty<T>())?
.Except(null) ?? Enumerable.Empty<T>())
.Distinct();
.Union(extends.DeclaringType?
.GetInterfaces()
.SelectMany(interfaceType => interfaceType
.GetMember(extends.Name,
extends.MemberType,
BindingFlags.Instance)
.FirstOrDefault()?
.GetCustomAttributes<T>(true) ??
Enumerable.Empty<T>())?
.Except(null) ?? Enumerable.Empty<T>())
.Distinct();
}
#endif
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Text;
using ICD.Common.Properties;
namespace ICD.Common.Utils.Extensions
{
@@ -9,7 +10,7 @@ namespace ICD.Common.Utils.Extensions
/// Empties the StringBuilder.
/// </summary>
/// <param name="extends"></param>
public static void Clear(this StringBuilder extends)
public static void Clear([NotNull] this StringBuilder extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -23,7 +24,7 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static string Pop(this StringBuilder extends)
public static string Pop([NotNull] this StringBuilder extends)
{
if (extends == null)
throw new ArgumentNullException("extends");

View File

@@ -15,7 +15,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="first"></param>
/// <returns></returns>
[PublicAPI]
public static int IndexOf(this string extends, IEnumerable<string> items, out string first)
public static int IndexOf([NotNull] this string extends, [NotNull] IEnumerable<string> items, out string first)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -52,7 +52,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="character"></param>
/// <returns></returns>
[PublicAPI]
public static bool StartsWith(this string extends, char character)
public static bool StartsWith([NotNull] this string extends, char character)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -67,7 +67,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="character"></param>
/// <returns></returns>
[PublicAPI]
public static bool EndsWith(this string extends, char character)
public static bool EndsWith([NotNull] this string extends, char character)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -83,7 +83,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="delimeter"></param>
/// <param name="count"></param>
/// <returns></returns>
public static IEnumerable<string> Split(this string extends, char delimeter, int count)
[NotNull]
public static IEnumerable<string> Split([NotNull] this string extends, char delimeter, int count)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -102,7 +103,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="delimeter"></param>
/// <param name="count"></param>
/// <returns></returns>
private static IEnumerable<string> SplitIterator(string value, char delimeter, int count)
[NotNull]
private static IEnumerable<string> SplitIterator([NotNull] string value, char delimeter, int count)
{
while (count > 1)
{
@@ -125,7 +127,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="chunkSize"></param>
/// <returns></returns>
[PublicAPI]
public static IEnumerable<string> Split(this string extends, int chunkSize)
[NotNull]
public static IEnumerable<string> Split([NotNull] this string extends, int chunkSize)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -134,7 +137,8 @@ namespace ICD.Common.Utils.Extensions
throw new InvalidOperationException("chunkSize must be greater than 0");
return Enumerable.Range(0, (int)Math.Ceiling(extends.Length / (double)chunkSize))
.Select(i => extends.Substring(i * chunkSize, Math.Min(chunkSize, extends.Length - (i * chunkSize))));
.Select(i => extends.Substring(i * chunkSize,
Math.Min(chunkSize, extends.Length - (i * chunkSize))));
}
/// <summary>
@@ -143,7 +147,8 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static string RemoveWhitespace(this string extends)
[NotNull]
public static string RemoveWhitespace([NotNull] this string extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -152,12 +157,13 @@ namespace ICD.Common.Utils.Extensions
}
/// <summary>
/// Removes all occurances of the given string.
/// Removes all occurrences of the given string.
/// </summary>
/// <param name="extends"></param>
/// <param name="other"></param>
/// <returns></returns>
public static string Remove(this string extends, string other)
[NotNull]
public static string Remove([NotNull] this string extends, [NotNull] string other)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -176,19 +182,21 @@ namespace ICD.Common.Utils.Extensions
}
/// <summary>
/// Removes all occurances the given characters from the string.
/// Removes all occurrences the given characters from the string.
/// </summary>
/// <param name="extends"></param>
/// <param name="characters"></param>
/// <returns></returns>
[PublicAPI]
public static string Remove(this string extends, IEnumerable<char> characters)
[NotNull]
public static string Remove([NotNull] this string extends, IEnumerable<char> characters)
{
if (extends == null)
throw new ArgumentNullException("extends");
if (characters == null)
throw new ArgumentNullException("characters");
var cSet = characters.ToIcdHashSet();
return new string(extends.Where(c => !cSet.Contains(c)).ToArray());
@@ -200,7 +208,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
public static bool IsNumeric(this string extends)
public static bool IsNumeric([NotNull] this string extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -214,7 +222,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="extends"></param>
/// <param name="character"></param>
/// <returns></returns>
public static bool Contains(this string extends, char character)
public static bool Contains([NotNull] this string extends, char character)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -227,8 +235,11 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static int GetStableHashCode(this string extends)
public static int GetStableHashCode([NotNull] this string extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
unchecked
{
int hash1 = 5381;

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICD.Common.Properties;
using ICD.Common.Utils.Collections;
#if SIMPLSHARP
using Crestron.SimplSharp.Reflection;
@@ -83,7 +84,7 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static bool CanBeNull(this Type extends)
public static bool CanBeNull([NotNull]this Type extends)
{
if (extends == null)
throw new ArgumentException("extends");
@@ -96,7 +97,7 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static bool IsNumeric(this Type extends)
public static bool IsNumeric([NotNull]this Type extends)
{
if (extends == null)
throw new ArgumentException("extends");
@@ -109,7 +110,7 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static bool IsSignedNumeric(this Type extends)
public static bool IsSignedNumeric([NotNull]this Type extends)
{
if (extends == null)
throw new ArgumentException("extends");
@@ -122,7 +123,7 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static bool IsDecimalNumeric(this Type extends)
public static bool IsDecimalNumeric([NotNull]this Type extends)
{
if (extends == null)
throw new ArgumentException("extends");
@@ -135,7 +136,7 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static bool IsIntegerNumeric(this Type extends)
public static bool IsIntegerNumeric([NotNull]this Type extends)
{
if (extends == null)
throw new ArgumentException("extends");
@@ -148,7 +149,8 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static Assembly GetAssembly(this Type extends)
[NotNull]
public static Assembly GetAssembly([NotNull]this Type extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -167,7 +169,7 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="from"></param>
/// <returns></returns>
public static bool IsAssignableTo<T>(this Type from)
public static bool IsAssignableTo<T>([NotNull]this Type from)
{
if (from == null)
throw new ArgumentNullException("from");
@@ -181,7 +183,7 @@ namespace ICD.Common.Utils.Extensions
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static bool IsAssignableTo(this Type from, Type to)
public static bool IsAssignableTo([NotNull]this Type from, [NotNull]Type to)
{
if (from == null)
throw new ArgumentNullException("from");
@@ -197,7 +199,8 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static IEnumerable<Type> GetAllTypes(this Type extends)
[NotNull]
public static IEnumerable<Type> GetAllTypes([NotNull]this Type extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -221,7 +224,8 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static IEnumerable<Type> GetBaseTypes(this Type extends)
[NotNull]
public static IEnumerable<Type> GetBaseTypes([NotNull]this Type extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -236,7 +240,8 @@ namespace ICD.Common.Utils.Extensions
return types;
}
private static IEnumerable<Type> GetBaseTypesIterator(Type type)
[NotNull]
private static IEnumerable<Type> GetBaseTypesIterator([NotNull] Type type)
{
do
{
@@ -257,7 +262,8 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static IEnumerable<Type> GetImmediateInterfaces(this Type extends)
[NotNull]
public static IEnumerable<Type> GetImmediateInterfaces([NotNull]this Type extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -286,7 +292,8 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static IEnumerable<Type> GetMinimalInterfaces(this Type extends)
[NotNull]
public static IEnumerable<Type> GetMinimalInterfaces([NotNull]this Type extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -314,7 +321,8 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static string GetNameWithoutGenericArity(this Type extends)
[NotNull]
public static string GetNameWithoutGenericArity([NotNull]this Type extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -330,7 +338,8 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static string GetMinimalName(this Type extends)
[NotNull]
public static string GetMinimalName([NotNull]this Type extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -380,7 +389,8 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static string GetNameWithoutAssemblyDetails(this Type extends)
[NotNull]
public static string GetNameWithoutAssemblyDetails([NotNull]this Type extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -401,7 +411,8 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="fullyQualifiedTypeName"></param>
/// <returns></returns>
private static string RemoveAssemblyDetails(string fullyQualifiedTypeName)
[NotNull]
private static string RemoveAssemblyDetails([NotNull] string fullyQualifiedTypeName)
{
StringBuilder builder = new StringBuilder();
@@ -450,7 +461,8 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends">Type. May be generic or nullable</param>
/// <returns>Full type name, fully qualified namespaces</returns>
public static string GetSyntaxName(this Type extends)
[NotNull]
public static string GetSyntaxName([NotNull]this Type extends)
{
if (extends == null)
throw new ArgumentNullException("extends");

View File

@@ -1,5 +1,6 @@
using System;
using System.Linq;
using ICD.Common.Properties;
namespace ICD.Common.Utils.Extensions
{
@@ -10,7 +11,8 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static string GetUserName(this Uri extends)
[NotNull]
public static string GetUserName([NotNull] this Uri extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
@@ -23,7 +25,8 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static string GetPassword(this Uri extends)
[NotNull]
public static string GetPassword([NotNull] this Uri extends)
{
if (extends == null)
throw new ArgumentNullException("extends");

View File

@@ -4,6 +4,7 @@ using System.Linq;
using ICD.Common.Properties;
using ICD.Common.Utils.Extensions;
using ICD.Common.Utils.IO;
using MethodInfoExtensions = ICD.Common.Utils.Extensions.MethodInfoExtensions;
#if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharp.Reflection;
@@ -373,7 +374,7 @@ namespace ICD.Common.Utils
object handler = eventHandler.Target;
// ReSharper disable InvokeAsExtensionMethod
MethodInfo callback = EventHandlerExtensions.GetMethodInfo(eventHandler);
MethodInfo callback = MethodInfoExtensions.GetMethodInfo(eventHandler);
// ReSharper restore InvokeAsExtensionMethod
return SubscribeEvent(instance, eventInfo, handler, callback);
@@ -397,7 +398,7 @@ namespace ICD.Common.Utils
object handler = eventHandler.Target;
// ReSharper disable InvokeAsExtensionMethod
MethodInfo callback = EventHandlerExtensions.GetMethodInfo(eventHandler);
MethodInfo callback = MethodInfoExtensions.GetMethodInfo(eventHandler);
// ReSharper restore InvokeAsExtensionMethod
return SubscribeEvent(instance, eventInfo, handler, callback);