This commit is contained in:
Drew Tingen
2017-07-03 02:54:13 -04:00
4 changed files with 29 additions and 4 deletions

View File

@@ -21,7 +21,7 @@ namespace ICD.Common.Utils
/// Returns true if the given type is an enum. /// Returns true if the given type is an enum.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private static bool IsEnum(Type type) public static bool IsEnum(Type type)
{ {
return type == typeof(Enum) || type return type == typeof(Enum) || type
#if !SIMPLSHARP #if !SIMPLSHARP
@@ -35,7 +35,7 @@ namespace ICD.Common.Utils
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <returns></returns> /// <returns></returns>
private static bool IsEnum<T>() public static bool IsEnum<T>()
{ {
return IsEnum(typeof(T)); return IsEnum(typeof(T));
} }

View File

@@ -1,4 +1,9 @@
using System; using System;
#if SIMPLSHARP
using Crestron.SimplSharp.Reflection;
#else
using System.Reflection;
#endif
namespace ICD.Common.Utils.Extensions namespace ICD.Common.Utils.Extensions
{ {

View File

@@ -9,6 +9,14 @@ namespace ICD.Common.Utils.IO
{ {
public static class IcdPath 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) public static string GetFileNameWithoutExtension(string path)
{ {
if (path == null) if (path == null)

View File

@@ -435,6 +435,9 @@ namespace ICD.Common.Utils.Xml
[PublicAPI] [PublicAPI]
public static T ReadChildElementContentAsEnum<T>(string xml, string childElement, bool ignoreCase) public static T ReadChildElementContentAsEnum<T>(string xml, string childElement, bool ignoreCase)
{ {
if (!EnumUtils.IsEnum<T>())
throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name));
string child = GetChildElementAsString(xml, childElement); string child = GetChildElementAsString(xml, childElement);
using (IcdXmlReader reader = new IcdXmlReader(child)) using (IcdXmlReader reader = new IcdXmlReader(child))
{ {
@@ -592,8 +595,11 @@ namespace ICD.Common.Utils.Xml
public static T? TryReadChildElementContentAsEnum<T>(string xml, string childElement, bool ignoreCase) public static T? TryReadChildElementContentAsEnum<T>(string xml, string childElement, bool ignoreCase)
where T : struct where T : struct
{ {
T? output; if (!EnumUtils.IsEnum<T>())
return !TryReadChildElementContentAsEnum(xml, childElement, ignoreCase, out output) ? null : output; 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;
} }
/// <summary> /// <summary>
@@ -608,6 +614,9 @@ namespace ICD.Common.Utils.Xml
[PublicAPI] [PublicAPI]
public static bool TryReadChildElementContentAsEnum<T>(string xml, string childElement, bool ignoreCase, out T output) public static bool TryReadChildElementContentAsEnum<T>(string xml, string childElement, bool ignoreCase, out T output)
{ {
if (!EnumUtils.IsEnum<T>())
throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name));
output = default(T); output = default(T);
try try
@@ -700,6 +709,9 @@ namespace ICD.Common.Utils.Xml
[PublicAPI] [PublicAPI]
public static T ReadElementContentAsEnum<T>(string xml, bool ignoreCase) public static T ReadElementContentAsEnum<T>(string xml, bool ignoreCase)
{ {
if (!EnumUtils.IsEnum<T>())
throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name));
using (IcdXmlReader reader = new IcdXmlReader(xml)) using (IcdXmlReader reader = new IcdXmlReader(xml))
{ {
reader.Read(); reader.Read();