mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
Whitespace
This commit is contained in:
@@ -83,7 +83,7 @@ namespace ICD.Common.Utils
|
||||
e.Message);
|
||||
}
|
||||
|
||||
foreach (var type in types)
|
||||
foreach (CType type in types)
|
||||
CacheType(type);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace ICD.Common.Utils
|
||||
#if !SIMPLSHARP
|
||||
.GetTypeInfo()
|
||||
#endif
|
||||
.IsEnum;
|
||||
.IsEnum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -225,14 +225,14 @@ namespace ICD.Common.Utils
|
||||
.IsDefined(typeof(FlagsAttribute), false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the overlapping values of the given enum flags.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <summary>
|
||||
/// Gets the overlapping values of the given enum flags.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="values"></param>
|
||||
/// <returns></returns>
|
||||
/// <returns></returns>
|
||||
public static T GetFlagsIntersection<T>(params T[] values)
|
||||
{
|
||||
{
|
||||
if (values.Length == 0)
|
||||
return GetNoneValue<T>();
|
||||
|
||||
@@ -240,8 +240,8 @@ namespace ICD.Common.Utils
|
||||
foreach (T item in values.Skip(1))
|
||||
output &= (int)(object)item;
|
||||
|
||||
return (T)Enum.ToObject(typeof(T), output);
|
||||
}
|
||||
return (T)Enum.ToObject(typeof(T), output);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all of the set flags on the given enum.
|
||||
@@ -374,27 +374,27 @@ namespace ICD.Common.Utils
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static bool HasAnyFlags<T>(T value)
|
||||
{
|
||||
return GetFlagsExceptNone(value).Any();
|
||||
}
|
||||
public static bool HasAnyFlags<T>(T value)
|
||||
{
|
||||
return GetFlagsExceptNone(value).Any();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the enum contains any of the given flag values.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="other"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static bool HasAnyFlags<T>(T value, T other)
|
||||
{
|
||||
T intersection = GetFlagsIntersection(value, other);
|
||||
return HasAnyFlags(intersection);
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns true if the enum contains any of the given flag values.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="other"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static bool HasAnyFlags<T>(T value, T other)
|
||||
{
|
||||
T intersection = GetFlagsIntersection(value, other);
|
||||
return HasAnyFlags(intersection);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Conversion
|
||||
#region Conversion
|
||||
|
||||
/// <summary>
|
||||
/// Shorthand for parsing string to enum.
|
||||
@@ -442,71 +442,71 @@ namespace ICD.Common.Utils
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shorthand for parsing string to enum.
|
||||
/// Will fail if the resulting value is not defined as part of the enum.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="ignoreCase"></param>
|
||||
/// <returns></returns>
|
||||
public static T ParseStrict<T>(string data, bool ignoreCase)
|
||||
{
|
||||
if (!IsEnumType<T>())
|
||||
throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name));
|
||||
/// <summary>
|
||||
/// Shorthand for parsing string to enum.
|
||||
/// Will fail if the resulting value is not defined as part of the enum.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="ignoreCase"></param>
|
||||
/// <returns></returns>
|
||||
public static T ParseStrict<T>(string data, bool ignoreCase)
|
||||
{
|
||||
if (!IsEnumType<T>())
|
||||
throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name));
|
||||
|
||||
T output;
|
||||
T output;
|
||||
|
||||
try
|
||||
{
|
||||
output = Parse<T>(data, ignoreCase);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new FormatException(
|
||||
string.Format("Failed to parse {0} as {1}", StringUtils.ToRepresentation(data), typeof(T).Name), e);
|
||||
}
|
||||
try
|
||||
{
|
||||
output = Parse<T>(data, ignoreCase);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new FormatException(
|
||||
string.Format("Failed to parse {0} as {1}", StringUtils.ToRepresentation(data), typeof(T).Name), e);
|
||||
}
|
||||
|
||||
if (!IsDefined(output))
|
||||
throw new ArgumentOutOfRangeException(string.Format("{0} is not a valid {1}", output, typeof(T).Name));
|
||||
if (!IsDefined(output))
|
||||
throw new ArgumentOutOfRangeException(string.Format("{0} is not a valid {1}", output, typeof(T).Name));
|
||||
|
||||
return output;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shorthand for parsing a string to enum. Returns false if the parse failed.
|
||||
/// Will fail if the resulting value is not defined as part of the enum.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="ignoreCase"></param>
|
||||
/// <param name="result"></param>
|
||||
/// <returns></returns>
|
||||
public static bool TryParseStrict<T>(string data, bool ignoreCase, out T result)
|
||||
{
|
||||
if (!IsEnumType<T>())
|
||||
throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name));
|
||||
/// <summary>
|
||||
/// Shorthand for parsing a string to enum. Returns false if the parse failed.
|
||||
/// Will fail if the resulting value is not defined as part of the enum.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="ignoreCase"></param>
|
||||
/// <param name="result"></param>
|
||||
/// <returns></returns>
|
||||
public static bool TryParseStrict<T>(string data, bool ignoreCase, out T result)
|
||||
{
|
||||
if (!IsEnumType<T>())
|
||||
throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name));
|
||||
|
||||
result = default(T);
|
||||
result = default(T);
|
||||
|
||||
try
|
||||
{
|
||||
result = ParseStrict<T>(data, ignoreCase);
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
result = ParseStrict<T>(data, ignoreCase);
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the given enum value to an Enum.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static Enum ToEnum<T>(T value)
|
||||
/// <summary>
|
||||
/// Converts the given enum value to an Enum.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static Enum ToEnum<T>(T value)
|
||||
{
|
||||
if (!IsEnum(value))
|
||||
// ReSharper disable once CompareNonConstrainedGenericWithNull
|
||||
|
||||
@@ -35,4 +35,4 @@ namespace ICD.Common.Utils.Extensions
|
||||
return (byte)(b & ~(1 << n));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,15 +8,15 @@ namespace ICD.Common.Utils.Extensions
|
||||
/// </summary>
|
||||
public static class DateTimeExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Replacement for missing DateTime.ToShortTimeString() absent from NetStandard.
|
||||
/// </summary>
|
||||
/// <param name="extends"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToShortTimeString(this DateTime extends)
|
||||
{
|
||||
return extends.ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern);
|
||||
}
|
||||
/// <summary>
|
||||
/// Replacement for missing DateTime.ToShortTimeString() absent from NetStandard.
|
||||
/// </summary>
|
||||
/// <param name="extends"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToShortTimeString(this DateTime extends)
|
||||
{
|
||||
return extends.ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a string representation of the DateTime with millisecond precision.
|
||||
|
||||
@@ -314,8 +314,8 @@ namespace ICD.Common.Utils.Extensions
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static bool DictionaryEqual<TKey, TValue>(this IDictionary<TKey, TValue> extends,
|
||||
IDictionary<TKey, TValue> other,
|
||||
Func<TValue, TValue, bool> valueComparer)
|
||||
IDictionary<TKey, TValue> other,
|
||||
Func<TValue, TValue, bool> valueComparer)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
@@ -126,7 +126,7 @@ 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>
|
||||
@@ -209,8 +209,6 @@ namespace ICD.Common.Utils.Extensions
|
||||
.SelectMany(s => s.Split(delimitersArray.Skip(1)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Removes whitespace from the string.
|
||||
/// </summary>
|
||||
|
||||
@@ -6,59 +6,59 @@ using System.Collections.Generic;
|
||||
|
||||
namespace ICD.Common.Utils.Extensions
|
||||
{
|
||||
public static class TypeExtensions
|
||||
{
|
||||
public static bool IsAssignableTo(this Type from, Type to)
|
||||
{
|
||||
if (from == null)
|
||||
throw new ArgumentNullException("from");
|
||||
public static class TypeExtensions
|
||||
{
|
||||
public static bool IsAssignableTo(this Type from, Type to)
|
||||
{
|
||||
if (from == null)
|
||||
throw new ArgumentNullException("from");
|
||||
|
||||
if (to == null)
|
||||
throw new ArgumentNullException("to");
|
||||
if (to == null)
|
||||
throw new ArgumentNullException("to");
|
||||
|
||||
return to.IsAssignableFrom(from);
|
||||
}
|
||||
return to.IsAssignableFrom(from);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the given type, all base types, and all implemented interfaces.
|
||||
/// </summary>
|
||||
/// <param name="extends"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Type> GetAllTypes(this Type extends)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
/// <summary>
|
||||
/// Returns the given type, all base types, and all implemented interfaces.
|
||||
/// </summary>
|
||||
/// <param name="extends"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Type> GetAllTypes(this Type extends)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
yield return extends;
|
||||
yield return extends;
|
||||
|
||||
foreach (Type type in extends.GetBaseTypes())
|
||||
yield return type;
|
||||
foreach (Type type in extends.GetBaseTypes())
|
||||
yield return type;
|
||||
|
||||
foreach (Type type in extends.GetInterfaces())
|
||||
yield return type;
|
||||
}
|
||||
foreach (Type type in extends.GetInterfaces())
|
||||
yield return type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all base types for the given type.
|
||||
/// </summary>
|
||||
/// <param name="extends"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Type> GetBaseTypes(this Type extends)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
/// <summary>
|
||||
/// Returns all base types for the given type.
|
||||
/// </summary>
|
||||
/// <param name="extends"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Type> GetBaseTypes(this Type extends)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
do
|
||||
{
|
||||
extends = extends
|
||||
do
|
||||
{
|
||||
extends = extends
|
||||
#if !SIMPLSHARP
|
||||
.GetTypeInfo()
|
||||
#endif
|
||||
.BaseType;
|
||||
.BaseType;
|
||||
|
||||
if (extends != null)
|
||||
yield return extends;
|
||||
} while (extends != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (extends != null)
|
||||
yield return extends;
|
||||
} while (extends != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#if SIMPLSHARP
|
||||
using Crestron.SimplSharp.CrestronIO;
|
||||
using GC = Crestron.SimplSharp.CrestronEnvironment.GC;
|
||||
|
||||
#else
|
||||
using System.IO;
|
||||
using GC = System.GC;
|
||||
@@ -46,9 +47,7 @@ namespace ICD.Common.Utils.IO
|
||||
return;
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
m_TextWriter.Dispose();
|
||||
}
|
||||
m_Disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace ICD.Common.Utils
|
||||
[PublicAPI]
|
||||
public static void ConsoleCommandResponse(string message, params object[] args)
|
||||
{
|
||||
if(args != null && args.Any())
|
||||
if (args != null && args.Any())
|
||||
message = string.Format(message, args);
|
||||
|
||||
#if SIMPLSHARP
|
||||
@@ -113,4 +113,4 @@ namespace ICD.Common.Utils
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ using System.Linq;
|
||||
|
||||
namespace ICD.Common.Utils
|
||||
{
|
||||
public static partial class ProgramUtils
|
||||
{
|
||||
public static partial class ProgramUtils
|
||||
{
|
||||
private const string APPLICATION_NAME_KEY = "Application Name";
|
||||
private const string APPLICATION_NAME_SIMPL_KEY = "System Name";
|
||||
private const string PROGRAM_FILE_KEY = "Program File";
|
||||
@@ -34,13 +34,7 @@ namespace ICD.Common.Utils
|
||||
/// Gets the program number.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public static uint ProgramNumber
|
||||
{
|
||||
get
|
||||
{
|
||||
return InitialParametersClass.ApplicationNumber;
|
||||
}
|
||||
}
|
||||
public static uint ProgramNumber { get { return InitialParametersClass.ApplicationNumber; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the compile date of the program.
|
||||
@@ -108,7 +102,7 @@ namespace ICD.Common.Utils
|
||||
return output;
|
||||
}
|
||||
|
||||
foreach (string line in progInfo.Split(new[] { "\n\r", "\r\n", "\n", "\r" }))
|
||||
foreach (string line in progInfo.Split(new[] {"\n\r", "\r\n", "\n", "\r"}))
|
||||
{
|
||||
if (string.IsNullOrEmpty(line))
|
||||
continue;
|
||||
@@ -118,7 +112,7 @@ namespace ICD.Common.Utils
|
||||
if (pair.Length < 2)
|
||||
{
|
||||
ServiceProvider.GetService<ILoggerService>()
|
||||
.AddEntry(eSeverity.Warning, "Failed to parse prog comments line - {0}", line);
|
||||
.AddEntry(eSeverity.Warning, "Failed to parse prog comments line - {0}", line);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace ICD.Common.Utils
|
||||
{
|
||||
private readonly object m_Instance;
|
||||
|
||||
private readonly List<string> m_PropertyOrder;
|
||||
private readonly Dictionary<string, object> m_PropertyValues;
|
||||
private readonly List<string> m_PropertyOrder;
|
||||
private readonly Dictionary<string, object> m_PropertyValues;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
|
||||
@@ -12,11 +12,11 @@ namespace ICD.Common.Utils
|
||||
{
|
||||
public static class ThreadingUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Executes the callback as a short-lived, threaded task.
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
[PublicAPI]
|
||||
/// <summary>
|
||||
/// Executes the callback as a short-lived, threaded task.
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
[PublicAPI]
|
||||
public static object SafeInvoke(Action callback)
|
||||
{
|
||||
return SafeInvoke<object>(unused => callback(), null);
|
||||
@@ -36,7 +36,7 @@ namespace ICD.Common.Utils
|
||||
#else
|
||||
return Task.Run(GetHandledCallback(callback, param));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wraps the given callback in a try/catch to avoid crashing crestron programs.
|
||||
@@ -46,19 +46,19 @@ namespace ICD.Common.Utils
|
||||
/// <param name="callback"></param>
|
||||
/// <param name="param"></param>
|
||||
private static Action GetHandledCallback<T>(Action<T> callback, T param)
|
||||
{
|
||||
return () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
callback(param);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ServiceProvider.TryGetService<ILoggerService>()
|
||||
.AddEntry(eSeverity.Error, e, e.Message);
|
||||
}
|
||||
};
|
||||
}
|
||||
{
|
||||
return () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
callback(param);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ServiceProvider.TryGetService<ILoggerService>()
|
||||
.AddEntry(eSeverity.Error, e, e.Message);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ICD.Common.Utils.EventArguments;
|
||||
using ICD.Common.Properties;
|
||||
using ICD.Common.Utils.EventArguments;
|
||||
#if SIMPLSHARP
|
||||
using Crestron.SimplSharp.CrestronXml;
|
||||
#else
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ICD.Common.Utils.EventArguments;
|
||||
using ICD.Common.Properties;
|
||||
using ICD.Common.Utils.EventArguments;
|
||||
using ICD.Common.Utils.Extensions;
|
||||
using ICD.Common.Utils.IO;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user