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.
/// </summary>
/// <returns></returns>
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
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
private static bool IsEnum<T>()
public static bool IsEnum<T>()
{
return IsEnum(typeof(T));
}

View File

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

View File

@@ -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)

View File

@@ -435,6 +435,9 @@ namespace ICD.Common.Utils.Xml
[PublicAPI]
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);
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)
where T : struct
{
T? output;
return !TryReadChildElementContentAsEnum(xml, childElement, ignoreCase, out output) ? null : output;
if (!EnumUtils.IsEnum<T>())
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>
@@ -608,6 +614,9 @@ namespace ICD.Common.Utils.Xml
[PublicAPI]
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);
try
@@ -700,6 +709,9 @@ namespace ICD.Common.Utils.Xml
[PublicAPI]
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))
{
reader.Read();