mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 12:07:05 +00:00
Merge branch 'dev' of https://cs-gogs.icdpf.net/Common/Utils into dev
This commit is contained in:
commit
467adc8f3a
3 changed files with 30 additions and 17 deletions
|
|
@ -2,7 +2,6 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
using ICD.Common.Utils.Collections;
|
|
||||||
using ICD.Common.Utils.Extensions;
|
using ICD.Common.Utils.Extensions;
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
|
@ -15,8 +14,15 @@ namespace ICD.Common.Utils
|
||||||
{
|
{
|
||||||
public static class EnumUtils
|
public static class EnumUtils
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<Type, IcdHashSet<object>> s_EnumValuesCache =
|
private static readonly Dictionary<Type, object[]> s_EnumValuesCache;
|
||||||
new Dictionary<Type, IcdHashSet<object>>();
|
|
||||||
|
/// <summary>
|
||||||
|
/// Static constructor.
|
||||||
|
/// </summary>
|
||||||
|
static EnumUtils()
|
||||||
|
{
|
||||||
|
s_EnumValuesCache = new Dictionary<Type, object[]>();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns true if the given type is an enum.
|
/// Returns true if the given type is an enum.
|
||||||
|
|
@ -119,7 +125,7 @@ namespace ICD.Common.Utils
|
||||||
|
|
||||||
// Reflection is slow and this method is called a lot, so we cache the results.
|
// Reflection is slow and this method is called a lot, so we cache the results.
|
||||||
if (!s_EnumValuesCache.ContainsKey(type))
|
if (!s_EnumValuesCache.ContainsKey(type))
|
||||||
s_EnumValuesCache[type] = GetValuesUncached(type).ToIcdHashSet();
|
s_EnumValuesCache[type] = GetValuesUncached(type).ToArray();
|
||||||
|
|
||||||
return s_EnumValuesCache[type];
|
return s_EnumValuesCache[type];
|
||||||
}
|
}
|
||||||
|
|
@ -527,17 +533,7 @@ namespace ICD.Common.Utils
|
||||||
// ReSharper disable once CompareNonConstrainedGenericWithNull
|
// ReSharper disable once CompareNonConstrainedGenericWithNull
|
||||||
throw new ArgumentException(string.Format("{0} is not an enum", value == null ? "NULL" : value.GetType().Name), "value");
|
throw new ArgumentException(string.Format("{0} is not an enum", value == null ? "NULL" : value.GetType().Name), "value");
|
||||||
|
|
||||||
return ToEnum((object)value);
|
return (Enum)(object)value;
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts the given enum value to an Enum.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="value"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static Enum ToEnum(object value)
|
|
||||||
{
|
|
||||||
return (Enum)value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,8 @@ namespace ICD.Common.Utils.Extensions
|
||||||
throw new ArgumentException(message);
|
throw new ArgumentException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong num = Convert.ToUInt64(value);
|
int num = (int)(object)value;
|
||||||
return (Convert.ToUInt64(extends) & num) == num;
|
return ((int)(object)extends & num) == num;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
@ -128,6 +129,22 @@ namespace ICD.Common.Utils.Timers
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Profiles getting each item from the enumerable.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="enumerable"></param>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<T> Profile<T>(IEnumerable<T> enumerable, string name)
|
||||||
|
{
|
||||||
|
using (IEnumerator<T> enumerator = enumerable.GetEnumerator())
|
||||||
|
{
|
||||||
|
while (Profile(() => enumerator.MoveNext(), name))
|
||||||
|
yield return enumerator.Current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void PrintProfile(IcdStopwatch stopwatch, string name)
|
private static void PrintProfile(IcdStopwatch stopwatch, string name)
|
||||||
{
|
{
|
||||||
long elapsed = stopwatch.ElapsedMilliseconds;
|
long elapsed = stopwatch.ElapsedMilliseconds;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue