| | 1 | | using System; |
| | 2 | | using System.ComponentModel; |
| | 3 | |
|
| | 4 | | namespace PropertyGridHelpers.Attributes |
| | 5 | | { |
| | 6 | | #if NET8_0_OR_GREATER |
| | 7 | | /// <summary> |
| | 8 | | /// Specifies a localized display name for a property, event, or other |
| | 9 | | /// member in a class. |
| | 10 | | /// </summary> |
| | 11 | | /// <seealso cref="LocalizedTextAttribute" /> |
| | 12 | | /// <param name="resourceKey">The key identifying the localized string in the resource file.</param> |
| | 13 | | /// <remarks> |
| | 14 | | /// Initializes a new instance of the <see cref="LocalizedDisplayNameAttribute" /> class. |
| | 15 | | /// </remarks> |
| | 16 | | /// <example> |
| | 17 | | /// <code language="csharp"> |
| | 18 | | /// [ResourcePath(nameof(TestControl))] |
| | 19 | | /// [TypeDescriptionProvider(typeof(LocalizedTypeDescriptionProvider))] |
| | 20 | | /// public partial class TestControl : UserControl |
| | 21 | | /// { |
| | 22 | | /// [LocalizedCategory("Category_Layout")] |
| | 23 | | /// [LocalizedDescription("Description_Scrollbar")] |
| | 24 | | /// [LocalizedDisplayName("DisplayName_Scrollbar")] |
| | 25 | | /// [Editor(typeof(FlagEnumUIEditor<EnumTextConverter<ScrollBars>>), typeof(UITypeEditor))] |
| | 26 | | /// [TypeConverter(typeof(EnumTextConverter<ScrollBars>))] |
| | 27 | | /// [DefaultValue(ScrollBars.None)] |
| | 28 | | /// [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] |
| | 29 | | /// [EditorBrowsable(EditorBrowsableState.Always)] |
| | 30 | | /// [Bindable(true)] |
| | 31 | | /// public ScrollBars Scrollbars |
| | 32 | | /// { |
| | 33 | | /// get => _Scrollbars; |
| | 34 | | /// set => _Scrollbars = value; |
| | 35 | | /// } |
| | 36 | | /// } |
| | 37 | | /// </code> |
| | 38 | | /// </example> |
| | 39 | | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Method, AllowMultiple = false) |
| 24 | 40 | | public class LocalizedDisplayNameAttribute(string resourceKey) : LocalizedTextAttribute(resourceKey) |
| | 41 | | { |
| | 42 | | #else |
| | 43 | | /// <summary> |
| | 44 | | /// Specifies a localized display name for a property, event, or other |
| | 45 | | /// member in a class. |
| | 46 | | /// </summary> |
| | 47 | | /// <seealso cref="LocalizedTextAttribute" /> |
| | 48 | | /// <remarks> |
| | 49 | | /// Initializes a new instance of the <see cref="LocalizedDisplayNameAttribute" /> class. |
| | 50 | | /// </remarks> |
| | 51 | | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Method, AllowMultiple = false) |
| | 52 | | public class LocalizedDisplayNameAttribute : LocalizedTextAttribute |
| | 53 | | { |
| | 54 | | /// <summary> |
| | 55 | | /// Initializes a new instance of the <see cref="LocalizedDisplayNameAttribute" /> class. |
| | 56 | | /// </summary> |
| | 57 | | /// <param name="resourceKey">The key identifying the localized string in the resource file.</param> |
| | 58 | | /// <example> |
| | 59 | | /// <code language="csharp"> |
| | 60 | | /// [ResourcePath(nameof(TestControl))] |
| | 61 | | /// [TypeDescriptionProvider(typeof(LocalizedTypeDescriptionProvider))] |
| | 62 | | /// public partial class TestControl : UserControl |
| | 63 | | /// { |
| | 64 | | /// [LocalizedCategory("Category_Layout")] |
| | 65 | | /// [LocalizedDescription("Description_Scrollbar")] |
| | 66 | | /// [LocalizedDisplayName("DisplayName_Scrollbar")] |
| | 67 | | /// [Editor(typeof(FlagEnumUIEditor<EnumTextConverter<ScrollBars>>), typeof(UITypeEditor)) |
| | 68 | | /// [TypeConverter(typeof(EnumTextConverter<ScrollBars>))] |
| | 69 | | /// [DefaultValue(ScrollBars.None)] |
| | 70 | | /// [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] |
| | 71 | | /// [EditorBrowsable(EditorBrowsableState.Always)] |
| | 72 | | /// [Bindable(true)] |
| | 73 | | /// public ScrollBars Scrollbars |
| | 74 | | /// { |
| | 75 | | /// get => _Scrollbars; |
| | 76 | | /// set => _Scrollbars = value; |
| | 77 | | /// } |
| | 78 | | /// } |
| | 79 | | /// </code> |
| | 80 | | /// </example> |
| 16 | 81 | | public LocalizedDisplayNameAttribute(string resourceKey) : base(resourceKey) |
| 8 | 82 | | { |
| 16 | 83 | | } |
| | 84 | | #endif |
| | 85 | |
|
| | 86 | | /// <summary> |
| | 87 | | /// Gets the <see cref="LocalizedDisplayNameAttribute"/> from the specified context. |
| | 88 | | /// </summary> |
| | 89 | | /// <param name="context">The context.</param> |
| | 90 | | /// <returns></returns> |
| | 91 | | public static new LocalizedDisplayNameAttribute Get(ITypeDescriptorContext context) => |
| 28 | 92 | | context == null || context.Instance == null || context.PropertyDescriptor == null |
| 28 | 93 | | ? null |
| 28 | 94 | | : Support.Support.GetFirstCustomAttribute<LocalizedDisplayNameAttribute>( |
| 28 | 95 | | Support.Support.GetPropertyInfo(context)); |
| | 96 | | } |
| | 97 | | } |