1234567891011121314151617181920212223242526 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- namespace Aitex.Sorter.UI.ViewModel
- {
- public static class EnumHelper
- {
- public static Dictionary<T, string> ToDictionary<T>()
- {
- var result = new Dictionary<T, string>();
- var values = Enum.GetValues(typeof(T));
- foreach (T value in values)
- {
- var fi = value.GetType().GetField(value.ToString());
- var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
- if (attributes.Length > 0)
- result.Add(value, attributes[0].Description);
- else
- result.Add(value, value.ToString());
- }
- return result;
- }
- }
- }
|