perf: Adding contrains for enum methods, faster HasFlag/s checks

This commit is contained in:
Chris Cameron
2018-07-26 10:56:08 -04:00
parent 1a87ce9f00
commit 668994be18
5 changed files with 71 additions and 66 deletions

View File

@@ -392,6 +392,7 @@ namespace ICD.Common.Utils.Xml
/// <returns></returns>
[PublicAPI]
public static T ReadElementContentAsEnum<T>(this IcdXmlReader extends, bool ignoreCase)
where T : struct, IConvertible
{
if (extends == null)
throw new ArgumentNullException("extends");

View File

@@ -422,6 +422,7 @@ namespace ICD.Common.Utils.Xml
/// <returns></returns>
[PublicAPI]
public static T ReadChildElementContentAsEnum<T>(string xml, string childElement, bool ignoreCase)
where T : struct, IConvertible
{
if (!EnumUtils.IsEnumType<T>())
throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name));
@@ -608,7 +609,7 @@ namespace ICD.Common.Utils.Xml
/// <returns></returns>
[PublicAPI]
public static T? TryReadChildElementContentAsEnum<T>(string xml, string childElement, bool ignoreCase)
where T : struct
where T : struct, IConvertible
{
if (!EnumUtils.IsEnumType<T>())
throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name));
@@ -628,6 +629,7 @@ namespace ICD.Common.Utils.Xml
/// <returns></returns>
[PublicAPI]
public static bool TryReadChildElementContentAsEnum<T>(string xml, string childElement, bool ignoreCase, out T output)
where T : struct, IConvertible
{
if (!EnumUtils.IsEnumType<T>())
throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name));
@@ -731,6 +733,7 @@ namespace ICD.Common.Utils.Xml
/// <returns></returns>
[PublicAPI]
public static T ReadElementContentAsEnum<T>(string xml, bool ignoreCase)
where T : struct, IConvertible
{
if (!EnumUtils.IsEnumType<T>())
throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name));