diff --git a/MatterControlLib/SlicerConfiguration/UIFields/EnumDisplayField.cs b/MatterControlLib/SlicerConfiguration/UIFields/EnumDisplayField.cs index f9181ee4a..db2f18a92 100644 --- a/MatterControlLib/SlicerConfiguration/UIFields/EnumDisplayField.cs +++ b/MatterControlLib/SlicerConfiguration/UIFields/EnumDisplayField.cs @@ -57,6 +57,17 @@ namespace MatterHackers.MatterControl.SlicerConfiguration // TODO: Violates UIField norms but consistent with past behavior - state is only correct at construction time, often reconstructed public string InitialValue { get; set; } + T GetAttribute(Enum value) + where T : Attribute + { + var type = value.GetType(); + var name = Enum.GetName(type, value); + return type.GetField(name) // I prefer to get attributes this way + .GetCustomAttributes(false) + .OfType() + .SingleOrDefault(); + } + public override void Initialize(int tabIndex) { // Enum keyed on name to friendly name @@ -64,23 +75,19 @@ namespace MatterHackers.MatterControl.SlicerConfiguration string GetDescription(Enum value) { - var type = value.GetType(); - - var name = Enum.GetName(type, value); - - if (name != null) + if (GetAttribute(value) is DescriptionAttribute attr) { - if (Attribute.GetCustomAttribute(property, property.PropertyType) is DescriptionAttribute attr) - { - return attr.Description; - } + return attr.Description; } - return name; + return null; } - var enumDescriptions = Enum.GetValues(property.PropertyType); - + var enumDescriptions = new List(); + foreach (var value in Enum.GetValues(property.PropertyType)) + { + enumDescriptions.Add(GetDescription((Enum)value)); + } switch (enumDisplayAttibute.Mode) { diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index 4855313e0..630ef7334 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit 4855313e067eeb317a9f0accb04b093dd6dfa02b +Subproject commit 630ef7334038b950c0a9287409c31ab5a70e6f36