-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show object type enum and description in UI
- Loading branch information
Showing
3 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
OpenKh.Tools.ObjentryEditor/Converters/EnumDescriptionConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Globalization; | ||
using System.Reflection; | ||
using System.Windows.Data; | ||
|
||
namespace OpenKh.Tools.ObjentryEditor.Converters | ||
{ | ||
public class EnumDescriptionConverter : IValueConverter | ||
{ | ||
private string GetEnumDescription(Enum enumObj) | ||
{ | ||
FieldInfo fieldInfo = enumObj.GetType().GetField(enumObj.ToString()); | ||
object[] attribArray = fieldInfo.GetCustomAttributes(false); | ||
|
||
if (attribArray.Length == 0) | ||
return enumObj.ToString(); | ||
else | ||
{ | ||
DescriptionAttribute attrib = null; | ||
|
||
foreach (var att in attribArray) | ||
{ | ||
if (att is DescriptionAttribute) | ||
attrib = att as DescriptionAttribute; | ||
} | ||
|
||
if (attrib != null) | ||
return attrib.Description; | ||
|
||
return enumObj.ToString(); | ||
} | ||
} | ||
|
||
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
Enum myEnum = (Enum)value; | ||
string description = GetEnumDescription(myEnum); | ||
return description; | ||
} | ||
|
||
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return string.Empty; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters