summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs
diff options
context:
space:
mode:
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs26
1 files changed, 24 insertions, 2 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs b/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs
index 0bbc746d7..657434f31 100644
--- a/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs
+++ b/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs
@@ -12,7 +12,10 @@ namespace HandBrake.ApplicationServices.Functions
/// <summary>
/// Enum Helpers
/// </summary>
- public class EnumHelper
+ /// <typeparam name="T">
+ /// The Type Parameter
+ /// </typeparam>
+ public class EnumHelper<T>
{
/// <summary>
/// Get the description of an Enum
@@ -23,7 +26,7 @@ namespace HandBrake.ApplicationServices.Functions
/// <returns>
/// The Description string
/// </returns>
- public static string GetDescription(Enum value)
+ public static string GetDescription(T value)
{
FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes =
@@ -31,5 +34,24 @@ namespace HandBrake.ApplicationServices.Functions
typeof(DescriptionAttribute), false);
return (attributes.Length > 0) ? attributes[0].Description : value.ToString();
}
+
+ /// <summary>
+ /// Get the Enumeration for a given Enum Description
+ /// </summary>
+ /// <param name="description">The String description</param>
+ /// <returns>The Enum Value</returns>
+ public static T GetValue(string description)
+ {
+ foreach (T val in Enum.GetValues(typeof(T)))
+ {
+ string currDescription = GetDescription(val);
+ if (currDescription == description)
+ {
+ return val;
+ }
+ }
+
+ throw new ArgumentOutOfRangeException("The Description for the enum was not recognized.");
+ }
}
}