Whitespace

This commit is contained in:
Chris Cameron
2017-09-27 13:49:13 -04:00
parent ac885e9837
commit d598d42cff
14 changed files with 174 additions and 183 deletions

View File

@@ -83,7 +83,7 @@ namespace ICD.Common.Utils
e.Message); e.Message);
} }
foreach (var type in types) foreach (CType type in types)
CacheType(type); CacheType(type);
} }

View File

@@ -31,7 +31,7 @@ namespace ICD.Common.Utils
#if !SIMPLSHARP #if !SIMPLSHARP
.GetTypeInfo() .GetTypeInfo()
#endif #endif
.IsEnum; .IsEnum;
} }
/// <summary> /// <summary>
@@ -225,14 +225,14 @@ namespace ICD.Common.Utils
.IsDefined(typeof(FlagsAttribute), false); .IsDefined(typeof(FlagsAttribute), false);
} }
/// <summary> /// <summary>
/// Gets the overlapping values of the given enum flags. /// Gets the overlapping values of the given enum flags.
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="values"></param> /// <param name="values"></param>
/// <returns></returns> /// <returns></returns>
public static T GetFlagsIntersection<T>(params T[] values) public static T GetFlagsIntersection<T>(params T[] values)
{ {
if (values.Length == 0) if (values.Length == 0)
return GetNoneValue<T>(); return GetNoneValue<T>();
@@ -240,8 +240,8 @@ namespace ICD.Common.Utils
foreach (T item in values.Skip(1)) foreach (T item in values.Skip(1))
output &= (int)(object)item; output &= (int)(object)item;
return (T)Enum.ToObject(typeof(T), output); return (T)Enum.ToObject(typeof(T), output);
} }
/// <summary> /// <summary>
/// Gets all of the set flags on the given enum. /// Gets all of the set flags on the given enum.
@@ -374,27 +374,27 @@ namespace ICD.Common.Utils
/// <param name="value"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
[PublicAPI] [PublicAPI]
public static bool HasAnyFlags<T>(T value) public static bool HasAnyFlags<T>(T value)
{ {
return GetFlagsExceptNone(value).Any(); return GetFlagsExceptNone(value).Any();
} }
/// <summary> /// <summary>
/// Returns true if the enum contains any of the given flag values. /// Returns true if the enum contains any of the given flag values.
/// </summary> /// </summary>
/// <param name="value"></param> /// <param name="value"></param>
/// <param name="other"></param> /// <param name="other"></param>
/// <returns></returns> /// <returns></returns>
[PublicAPI] [PublicAPI]
public static bool HasAnyFlags<T>(T value, T other) public static bool HasAnyFlags<T>(T value, T other)
{ {
T intersection = GetFlagsIntersection(value, other); T intersection = GetFlagsIntersection(value, other);
return HasAnyFlags(intersection); return HasAnyFlags(intersection);
} }
#endregion #endregion
#region Conversion #region Conversion
/// <summary> /// <summary>
/// Shorthand for parsing string to enum. /// Shorthand for parsing string to enum.
@@ -442,71 +442,71 @@ namespace ICD.Common.Utils
} }
} }
/// <summary> /// <summary>
/// Shorthand for parsing string to enum. /// Shorthand for parsing string to enum.
/// Will fail if the resulting value is not defined as part of the enum. /// Will fail if the resulting value is not defined as part of the enum.
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="data"></param> /// <param name="data"></param>
/// <param name="ignoreCase"></param> /// <param name="ignoreCase"></param>
/// <returns></returns> /// <returns></returns>
public static T ParseStrict<T>(string data, bool ignoreCase) public static T ParseStrict<T>(string data, bool ignoreCase)
{ {
if (!IsEnumType<T>()) if (!IsEnumType<T>())
throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name)); throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name));
T output; T output;
try try
{ {
output = Parse<T>(data, ignoreCase); output = Parse<T>(data, ignoreCase);
} }
catch (Exception e) catch (Exception e)
{ {
throw new FormatException( throw new FormatException(
string.Format("Failed to parse {0} as {1}", StringUtils.ToRepresentation(data), typeof(T).Name), e); string.Format("Failed to parse {0} as {1}", StringUtils.ToRepresentation(data), typeof(T).Name), e);
} }
if (!IsDefined(output)) if (!IsDefined(output))
throw new ArgumentOutOfRangeException(string.Format("{0} is not a valid {1}", output, typeof(T).Name)); throw new ArgumentOutOfRangeException(string.Format("{0} is not a valid {1}", output, typeof(T).Name));
return output; return output;
} }
/// <summary> /// <summary>
/// Shorthand for parsing a string to enum. Returns false if the parse failed. /// 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. /// Will fail if the resulting value is not defined as part of the enum.
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="data"></param> /// <param name="data"></param>
/// <param name="ignoreCase"></param> /// <param name="ignoreCase"></param>
/// <param name="result"></param> /// <param name="result"></param>
/// <returns></returns> /// <returns></returns>
public static bool TryParseStrict<T>(string data, bool ignoreCase, out T result) public static bool TryParseStrict<T>(string data, bool ignoreCase, out T result)
{ {
if (!IsEnumType<T>()) if (!IsEnumType<T>())
throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name)); throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name));
result = default(T); result = default(T);
try try
{ {
result = ParseStrict<T>(data, ignoreCase); result = ParseStrict<T>(data, ignoreCase);
return true; return true;
} }
catch (Exception) catch (Exception)
{ {
return false; return false;
} }
} }
/// <summary> /// <summary>
/// Converts the given enum value to an Enum. /// Converts the given enum value to an Enum.
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="value"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
public static Enum ToEnum<T>(T value) public static Enum ToEnum<T>(T value)
{ {
if (!IsEnum(value)) if (!IsEnum(value))
// ReSharper disable once CompareNonConstrainedGenericWithNull // ReSharper disable once CompareNonConstrainedGenericWithNull

View File

@@ -8,15 +8,15 @@ namespace ICD.Common.Utils.Extensions
/// </summary> /// </summary>
public static class DateTimeExtensions public static class DateTimeExtensions
{ {
/// <summary> /// <summary>
/// Replacement for missing DateTime.ToShortTimeString() absent from NetStandard. /// Replacement for missing DateTime.ToShortTimeString() absent from NetStandard.
/// </summary> /// </summary>
/// <param name="extends"></param> /// <param name="extends"></param>
/// <returns></returns> /// <returns></returns>
public static string ToShortTimeString(this DateTime extends) public static string ToShortTimeString(this DateTime extends)
{ {
return extends.ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern); return extends.ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern);
} }
/// <summary> /// <summary>
/// Gets a string representation of the DateTime with millisecond precision. /// Gets a string representation of the DateTime with millisecond precision.

View File

@@ -314,8 +314,8 @@ namespace ICD.Common.Utils.Extensions
/// <returns></returns> /// <returns></returns>
[PublicAPI] [PublicAPI]
public static bool DictionaryEqual<TKey, TValue>(this IDictionary<TKey, TValue> extends, public static bool DictionaryEqual<TKey, TValue>(this IDictionary<TKey, TValue> extends,
IDictionary<TKey, TValue> other, IDictionary<TKey, TValue> other,
Func<TValue, TValue, bool> valueComparer) Func<TValue, TValue, bool> valueComparer)
{ {
if (extends == null) if (extends == null)
throw new ArgumentNullException("extends"); throw new ArgumentNullException("extends");

View File

@@ -126,7 +126,7 @@ namespace ICD.Common.Utils.Extensions
throw new InvalidOperationException("chunkSize must be greater than 0"); throw new InvalidOperationException("chunkSize must be greater than 0");
return Enumerable.Range(0, (int)Math.Ceiling(extends.Length / (double)chunkSize)) 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> /// <summary>
@@ -209,8 +209,6 @@ namespace ICD.Common.Utils.Extensions
.SelectMany(s => s.Split(delimitersArray.Skip(1))); .SelectMany(s => s.Split(delimitersArray.Skip(1)));
} }
/// <summary> /// <summary>
/// Removes whitespace from the string. /// Removes whitespace from the string.
/// </summary> /// </summary>

View File

@@ -6,59 +6,59 @@ using System.Collections.Generic;
namespace ICD.Common.Utils.Extensions namespace ICD.Common.Utils.Extensions
{ {
public static class TypeExtensions public static class TypeExtensions
{ {
public static bool IsAssignableTo(this Type from, Type to) public static bool IsAssignableTo(this Type from, Type to)
{ {
if (from == null) if (from == null)
throw new ArgumentNullException("from"); throw new ArgumentNullException("from");
if (to == null) if (to == null)
throw new ArgumentNullException("to"); throw new ArgumentNullException("to");
return to.IsAssignableFrom(from); return to.IsAssignableFrom(from);
} }
/// <summary> /// <summary>
/// Returns the given type, all base types, and all implemented interfaces. /// Returns the given type, all base types, and all implemented interfaces.
/// </summary> /// </summary>
/// <param name="extends"></param> /// <param name="extends"></param>
/// <returns></returns> /// <returns></returns>
public static IEnumerable<Type> GetAllTypes(this Type extends) public static IEnumerable<Type> GetAllTypes(this Type extends)
{ {
if (extends == null) if (extends == null)
throw new ArgumentNullException("extends"); throw new ArgumentNullException("extends");
yield return extends; yield return extends;
foreach (Type type in extends.GetBaseTypes()) foreach (Type type in extends.GetBaseTypes())
yield return type; yield return type;
foreach (Type type in extends.GetInterfaces()) foreach (Type type in extends.GetInterfaces())
yield return type; yield return type;
} }
/// <summary> /// <summary>
/// Returns all base types for the given type. /// Returns all base types for the given type.
/// </summary> /// </summary>
/// <param name="extends"></param> /// <param name="extends"></param>
/// <returns></returns> /// <returns></returns>
public static IEnumerable<Type> GetBaseTypes(this Type extends) public static IEnumerable<Type> GetBaseTypes(this Type extends)
{ {
if (extends == null) if (extends == null)
throw new ArgumentNullException("extends"); throw new ArgumentNullException("extends");
do do
{ {
extends = extends extends = extends
#if !SIMPLSHARP #if !SIMPLSHARP
.GetTypeInfo() .GetTypeInfo()
#endif #endif
.BaseType; .BaseType;
if (extends != null) if (extends != null)
yield return extends; yield return extends;
} while (extends != null); } while (extends != null);
} }
} }
} }

View File

@@ -2,6 +2,7 @@
#if SIMPLSHARP #if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharp.CrestronIO;
using GC = Crestron.SimplSharp.CrestronEnvironment.GC; using GC = Crestron.SimplSharp.CrestronEnvironment.GC;
#else #else
using System.IO; using System.IO;
using GC = System.GC; using GC = System.GC;
@@ -46,9 +47,7 @@ namespace ICD.Common.Utils.IO
return; return;
if (disposing) if (disposing)
{
m_TextWriter.Dispose(); m_TextWriter.Dispose();
}
m_Disposed = true; m_Disposed = true;
} }
} }

View File

@@ -35,7 +35,7 @@ namespace ICD.Common.Utils
[PublicAPI] [PublicAPI]
public static void ConsoleCommandResponse(string message, params object[] args) public static void ConsoleCommandResponse(string message, params object[] args)
{ {
if(args != null && args.Any()) if (args != null && args.Any())
message = string.Format(message, args); message = string.Format(message, args);
#if SIMPLSHARP #if SIMPLSHARP

View File

@@ -10,8 +10,8 @@ using System.Linq;
namespace ICD.Common.Utils 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_KEY = "Application Name";
private const string APPLICATION_NAME_SIMPL_KEY = "System Name"; private const string APPLICATION_NAME_SIMPL_KEY = "System Name";
private const string PROGRAM_FILE_KEY = "Program File"; private const string PROGRAM_FILE_KEY = "Program File";
@@ -34,13 +34,7 @@ namespace ICD.Common.Utils
/// Gets the program number. /// Gets the program number.
/// </summary> /// </summary>
[PublicAPI] [PublicAPI]
public static uint ProgramNumber public static uint ProgramNumber { get { return InitialParametersClass.ApplicationNumber; } }
{
get
{
return InitialParametersClass.ApplicationNumber;
}
}
/// <summary> /// <summary>
/// Gets the compile date of the program. /// Gets the compile date of the program.
@@ -108,7 +102,7 @@ namespace ICD.Common.Utils
return output; 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)) if (string.IsNullOrEmpty(line))
continue; continue;
@@ -118,7 +112,7 @@ namespace ICD.Common.Utils
if (pair.Length < 2) if (pair.Length < 2)
{ {
ServiceProvider.GetService<ILoggerService>() 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; continue;
} }

View File

@@ -12,11 +12,11 @@ namespace ICD.Common.Utils
{ {
public static class ThreadingUtils public static class ThreadingUtils
{ {
/// <summary> /// <summary>
/// Executes the callback as a short-lived, threaded task. /// Executes the callback as a short-lived, threaded task.
/// </summary> /// </summary>
/// <param name="callback"></param> /// <param name="callback"></param>
[PublicAPI] [PublicAPI]
public static object SafeInvoke(Action callback) public static object SafeInvoke(Action callback)
{ {
return SafeInvoke<object>(unused => callback(), null); return SafeInvoke<object>(unused => callback(), null);
@@ -36,7 +36,7 @@ namespace ICD.Common.Utils
#else #else
return Task.Run(GetHandledCallback(callback, param)); return Task.Run(GetHandledCallback(callback, param));
#endif #endif
} }
/// <summary> /// <summary>
/// Wraps the given callback in a try/catch to avoid crashing crestron programs. /// 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="callback"></param>
/// <param name="param"></param> /// <param name="param"></param>
private static Action GetHandledCallback<T>(Action<T> callback, T param) private static Action GetHandledCallback<T>(Action<T> callback, T param)
{ {
return () => return () =>
{ {
try try
{ {
callback(param); callback(param);
} }
catch (Exception e) catch (Exception e)
{ {
ServiceProvider.TryGetService<ILoggerService>() ServiceProvider.TryGetService<ILoggerService>()
.AddEntry(eSeverity.Error, e, e.Message); .AddEntry(eSeverity.Error, e, e.Message);
} }
}; };
} }
} }
} }

View File

@@ -1,8 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using ICD.Common.Utils.EventArguments;
using ICD.Common.Properties; using ICD.Common.Properties;
using ICD.Common.Utils.EventArguments;
#if SIMPLSHARP #if SIMPLSHARP
using Crestron.SimplSharp.CrestronXml; using Crestron.SimplSharp.CrestronXml;
#else #else

View File

@@ -2,8 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using ICD.Common.Utils.EventArguments;
using ICD.Common.Properties; using ICD.Common.Properties;
using ICD.Common.Utils.EventArguments;
using ICD.Common.Utils.Extensions; using ICD.Common.Utils.Extensions;
using ICD.Common.Utils.IO; using ICD.Common.Utils.IO;