summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Utilities
diff options
context:
space:
mode:
authorsr55 <[email protected]>2018-06-05 19:32:36 +0100
committersr55 <[email protected]>2018-06-05 19:32:36 +0100
commit5445592f20e5e645dce0df077afe7ecc2617b95f (patch)
tree790ac24d94aa8bdd75b8704e990664b4d350d784 /win/CS/HandBrakeWPF/Utilities
parentce3a757ef8bbb723d0b233830531acac0b5da004 (diff)
WinGui: Additional Error Handling in EnumHelper
Diffstat (limited to 'win/CS/HandBrakeWPF/Utilities')
-rw-r--r--win/CS/HandBrakeWPF/Utilities/EnumHelper.cs29
1 files changed, 23 insertions, 6 deletions
diff --git a/win/CS/HandBrakeWPF/Utilities/EnumHelper.cs b/win/CS/HandBrakeWPF/Utilities/EnumHelper.cs
index c4ceaeb94..718533aab 100644
--- a/win/CS/HandBrakeWPF/Utilities/EnumHelper.cs
+++ b/win/CS/HandBrakeWPF/Utilities/EnumHelper.cs
@@ -44,10 +44,15 @@ namespace HandBrakeWPF.Utilities
}
FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
- DescriptionAttribute[] attributes =
+ if (fieldInfo != null)
+ {
+ DescriptionAttribute[] attributes =
(DescriptionAttribute[])fieldInfo.GetCustomAttributes(
typeof(DescriptionAttribute), false);
- return (attributes.Length > 0) ? attributes[0].Description : value.ToString();
+ return (attributes.Length > 0) ? attributes[0].Description : value.ToString();
+ }
+
+ return string.Empty;
}
/// <summary>
@@ -63,9 +68,14 @@ namespace HandBrakeWPF.Utilities
}
FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
- DisplayName[] attributes = (DisplayName[])fieldInfo.GetCustomAttributes(typeof(DisplayName), false);
+ if (fieldInfo != null)
+ {
+ DisplayName[] attributes = (DisplayName[])fieldInfo.GetCustomAttributes(typeof(DisplayName), false);
+
+ return (attributes.Length > 0) ? attributes[0].Name : value.ToString();
+ }
- return (attributes.Length > 0) ? attributes[0].Name : value.ToString();
+ return string.Empty;
}
/// <summary>
@@ -124,9 +134,13 @@ namespace HandBrakeWPF.Utilities
}
FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
- ShortName[] attributes = (ShortName[])fieldInfo.GetCustomAttributes(typeof(ShortName), false);
+ if (fieldInfo != null)
+ {
+ ShortName[] attributes = (ShortName[])fieldInfo.GetCustomAttributes(typeof(ShortName), false);
+ return (attributes.Length > 0) ? attributes[0].Name : value.ToString();
+ }
- return (attributes.Length > 0) ? attributes[0].Name : value.ToString();
+ return string.Empty;
}
/// <summary>
@@ -153,7 +167,10 @@ namespace HandBrakeWPF.Utilities
{
var strings = new Collection<string>();
foreach (T e in Enum.GetValues(enumType))
+ {
strings.Add(GetDisplay(e));
+ }
+
return strings;
}