From 7c10a3d41e9c1252e0f0afe85dad1dfc94532fc1 Mon Sep 17 00:00:00 2001 From: "jeff.thompson" Date: Fri, 30 Jun 2017 16:44:55 -0400 Subject: [PATCH 1/4] Fixed missing namespace --- ICD.Common.Utils/Utils/Extensions/TypeExtensions.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ICD.Common.Utils/Utils/Extensions/TypeExtensions.cs b/ICD.Common.Utils/Utils/Extensions/TypeExtensions.cs index 2b2475d..9f14cec 100644 --- a/ICD.Common.Utils/Utils/Extensions/TypeExtensions.cs +++ b/ICD.Common.Utils/Utils/Extensions/TypeExtensions.cs @@ -1,4 +1,9 @@ using System; +#if SIMPLSHARP +using Crestron.SimplSharp.Reflection; +#else +using System.Reflection; +#endif namespace ICD.Common.Utils.Extensions { From 1c52eca1dd6265703bb64b74c92e83803b663054 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Sun, 2 Jul 2017 10:42:19 -0400 Subject: [PATCH 2/4] Exposing Path.GetFileName(path) --- ICD.Common.Utils/Utils/IO/IcdPath.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ICD.Common.Utils/Utils/IO/IcdPath.cs b/ICD.Common.Utils/Utils/IO/IcdPath.cs index 6ec3f9a..c60ff5f 100644 --- a/ICD.Common.Utils/Utils/IO/IcdPath.cs +++ b/ICD.Common.Utils/Utils/IO/IcdPath.cs @@ -9,6 +9,14 @@ namespace ICD.Common.Utils.IO { public static class IcdPath { + public static string GetFileName(string path) + { + if (path == null) + throw new ArgumentNullException("path"); + + return Path.GetFileName(path); + } + public static string GetFileNameWithoutExtension(string path) { if (path == null) From 438b220a4dab346f773f6db83dfb8e4f5d3d4b18 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Sun, 2 Jul 2017 11:07:16 -0400 Subject: [PATCH 3/4] Fixing bug that prevented enums from being parsed from xml properly --- ICD.Common.Utils/Utils/Xml/XmlUtils.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ICD.Common.Utils/Utils/Xml/XmlUtils.cs b/ICD.Common.Utils/Utils/Xml/XmlUtils.cs index 4c3f65f..3f30879 100644 --- a/ICD.Common.Utils/Utils/Xml/XmlUtils.cs +++ b/ICD.Common.Utils/Utils/Xml/XmlUtils.cs @@ -592,8 +592,8 @@ namespace ICD.Common.Utils.Xml public static T? TryReadChildElementContentAsEnum(string xml, string childElement, bool ignoreCase) where T : struct { - T? output; - return !TryReadChildElementContentAsEnum(xml, childElement, ignoreCase, out output) ? null : output; + T output; + return TryReadChildElementContentAsEnum(xml, childElement, ignoreCase, out output) ? output : (T?)null; } /// From 03cb49ba943c06a7f846b92f994b70f8bf5f9196 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Sun, 2 Jul 2017 17:47:24 -0400 Subject: [PATCH 4/4] Validating enum types in xml utils --- ICD.Common.Utils/Utils/EnumUtils.cs | 4 ++-- ICD.Common.Utils/Utils/Xml/XmlUtils.cs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ICD.Common.Utils/Utils/EnumUtils.cs b/ICD.Common.Utils/Utils/EnumUtils.cs index ef7ec7f..4d540ee 100644 --- a/ICD.Common.Utils/Utils/EnumUtils.cs +++ b/ICD.Common.Utils/Utils/EnumUtils.cs @@ -21,7 +21,7 @@ namespace ICD.Common.Utils /// Returns true if the given type is an enum. /// /// - private static bool IsEnum(Type type) + public static bool IsEnum(Type type) { return type == typeof(Enum) || type #if !SIMPLSHARP @@ -35,7 +35,7 @@ namespace ICD.Common.Utils /// /// /// - private static bool IsEnum() + public static bool IsEnum() { return IsEnum(typeof(T)); } diff --git a/ICD.Common.Utils/Utils/Xml/XmlUtils.cs b/ICD.Common.Utils/Utils/Xml/XmlUtils.cs index 3f30879..5413c94 100644 --- a/ICD.Common.Utils/Utils/Xml/XmlUtils.cs +++ b/ICD.Common.Utils/Utils/Xml/XmlUtils.cs @@ -435,6 +435,9 @@ namespace ICD.Common.Utils.Xml [PublicAPI] public static T ReadChildElementContentAsEnum(string xml, string childElement, bool ignoreCase) { + if (!EnumUtils.IsEnum()) + throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name)); + string child = GetChildElementAsString(xml, childElement); using (IcdXmlReader reader = new IcdXmlReader(child)) { @@ -592,6 +595,9 @@ namespace ICD.Common.Utils.Xml public static T? TryReadChildElementContentAsEnum(string xml, string childElement, bool ignoreCase) where T : struct { + if (!EnumUtils.IsEnum()) + throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name)); + T output; return TryReadChildElementContentAsEnum(xml, childElement, ignoreCase, out output) ? output : (T?)null; } @@ -608,6 +614,9 @@ namespace ICD.Common.Utils.Xml [PublicAPI] public static bool TryReadChildElementContentAsEnum(string xml, string childElement, bool ignoreCase, out T output) { + if (!EnumUtils.IsEnum()) + throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name)); + output = default(T); try @@ -700,6 +709,9 @@ namespace ICD.Common.Utils.Xml [PublicAPI] public static T ReadElementContentAsEnum(string xml, bool ignoreCase) { + if (!EnumUtils.IsEnum()) + throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name)); + using (IcdXmlReader reader = new IcdXmlReader(xml)) { reader.Read();