I am currently working on upgrading a generic Windows 8.1 application to a Windows 10 UWP application. There is a piece of code that worked perfectly before it did not work in my Windows 10 UWP application.
I have an enumeration that looks like this:
public enum EStaticFile { [StringValue("Path of a file")] CONFIG_FILE_1, [StringValue("Path of a file")] CONFIG_FILE_2 }
When I try to get an attribute for any of the enum values, it always returns an empty array. I am using the following code:
public static StringValue GetStringValueAttribute(this Enum aEnumValue) { Type type = aEnumValue.GetType(); FieldInfo fieldInfo = type.GetRuntimeField(aEnumValue.ToString()); StringValue[] attributes = fieldInfo.GetCustomAttributes(typeof(StringValue), false) as StringValue[]; if (attributes.Length > 0) { return attributes[0]; } return null; }
GetCustomAttributes always returns an empty array, therefore attributes. The length is always 0, so the function returns null;
Has something changed in Windows 10 so it doesn't work?
Thanks a lot!
source share