mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-19 06:34:59 +00:00
Merge branch 'dev' of https://cs-gogs.icdpf.net/Common/Utils into dev
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
using System;
|
||||
#if SIMPLSHARP
|
||||
using Crestron.SimplSharp.Reflection;
|
||||
#else
|
||||
using System.Reflection;
|
||||
#endif
|
||||
|
||||
namespace ICD.Common.Utils.Extensions
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user