| | 1 | | using PropertyGridHelpers.Attributes; |
| | 2 | | using System; |
| | 3 | | using System.ComponentModel; |
| | 4 | | using System.Windows.Forms; |
| | 5 | |
|
| | 6 | | namespace PropertyGridHelpers.Converters |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// A strongly-typed generic version of <see cref="EnumTextConverter"/> for handling enums with |
| | 10 | | /// display text annotations in a <see cref="PropertyGrid"/>. |
| | 11 | | /// </summary> |
| | 12 | | /// <typeparam name="T"> |
| | 13 | | /// The enumeration type whose members are decorated with <see cref="EnumTextAttribute"/>. |
| | 14 | | /// </typeparam> |
| | 15 | | /// <remarks> |
| | 16 | | /// This converter simplifies using <see cref="EnumTextAttribute"/> on enum members |
| | 17 | | /// by automatically associating the generic parameter <typeparamref name="T"/> as |
| | 18 | | /// the enum to convert. This enables the property grid to display friendly |
| | 19 | | /// names for enum values without requiring manual type configuration. |
| | 20 | | /// </remarks> |
| | 21 | | /// <example> |
| | 22 | | /// <code> |
| | 23 | | /// public enum Status |
| | 24 | | /// { |
| | 25 | | /// [EnumText("Pending Approval")] |
| | 26 | | /// Pending, |
| | 27 | | /// |
| | 28 | | /// [EnumText("Approved")] |
| | 29 | | /// Approved, |
| | 30 | | /// |
| | 31 | | /// [EnumText("Rejected")] |
| | 32 | | /// Rejected |
| | 33 | | /// } |
| | 34 | | /// |
| | 35 | | /// [TypeConverter(typeof(EnumTextConverter<Status>))] |
| | 36 | | /// public Status CurrentStatus { get; set; } |
| | 37 | | /// </code> |
| | 38 | | /// </example> |
| | 39 | | /// <seealso cref="EnumTextAttribute"/> |
| | 40 | | /// <seealso cref="EnumConverter"/> |
| | 41 | | public partial class EnumTextConverter<T> : EnumTextConverter where T : Enum |
| | 42 | | { |
| | 43 | | /// <summary> |
| | 44 | | /// Initializes a new instance of the <see cref="EnumTextConverter" /> class. |
| | 45 | | /// </summary> |
| 276 | 46 | | public EnumTextConverter() : base(typeof(T)) { } |
| | 47 | | } |
| | 48 | | } |