| | 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 description for a property, event, or other member in a class. |
| | 9 | | /// </summary> |
| | 10 | | /// <remarks> |
| | 11 | | /// This attribute holds the key to the resource entry to get the description text from a resource file, allowing |
| | 12 | | /// descriptions to be localized. Apply this attribute to a member, providing the resource key. It is expected |
| | 13 | | /// to work together with the <see cref="ResourcePathAttribute"/> to figure out where to get the resource string |
| | 14 | | /// from |
| | 15 | | /// </remarks> |
| | 16 | | /// <seealso cref="Attribute" /> |
| | 17 | | /// <param name="resourceKey">The key identifying the localized string in the resource file.</param> |
| | 18 | | /// <example> |
| | 19 | | /// <code language="csharp"> |
| | 20 | | /// [ResourcePath(nameof(TestControl))] |
| | 21 | | /// [TypeDescriptionProvider(typeof(LocalizedTypeDescriptionProvider))] |
| | 22 | | /// public partial class TestControl : UserControl |
| | 23 | | /// { |
| | 24 | | /// [LocalizedCategory("Category_Layout")] |
| | 25 | | /// [LocalizedDescription("Description_Scrollbar")] |
| | 26 | | /// [LocalizedDisplayName("DisplayName_Scrollbar")] |
| | 27 | | /// [Editor(typeof(FlagEnumUIEditor<EnumTextConverter<ScrollBars>>), typeof(UITypeEditor))] |
| | 28 | | /// [TypeConverter(typeof(EnumTextConverter<ScrollBars>))] |
| | 29 | | /// [DefaultValue(ScrollBars.None)] |
| | 30 | | /// [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] |
| | 31 | | /// [EditorBrowsable(EditorBrowsableState.Always)] |
| | 32 | | /// [Bindable(true)] |
| | 33 | | /// public ScrollBars Scrollbars |
| | 34 | | /// { |
| | 35 | | /// get => _Scrollbars; |
| | 36 | | /// set => _Scrollbars = value; |
| | 37 | | /// } |
| | 38 | | /// } |
| | 39 | | /// </code> |
| | 40 | | /// </example> |
| | 41 | | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Method, AllowMultiple = false) |
| 24 | 42 | | public class LocalizedDescriptionAttribute(string resourceKey) : LocalizedTextAttribute(resourceKey) |
| | 43 | | { |
| | 44 | | #else |
| | 45 | | /// <summary> |
| | 46 | | /// Specifies a localized description for a property, event, or other member in a class. |
| | 47 | | /// </summary> |
| | 48 | | /// <remarks> |
| | 49 | | /// This attribute retrieves the description text from a resource file, allowing descriptions to be localized. |
| | 50 | | /// Apply this attribute to a member, providing the resource key and the resource source type containing the localiz |
| | 51 | | /// </remarks> |
| | 52 | | /// <seealso cref="Attribute" /> |
| | 53 | | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Method, AllowMultiple = false) |
| | 54 | | public class LocalizedDescriptionAttribute : LocalizedTextAttribute |
| | 55 | | { |
| | 56 | | /// <summary> |
| | 57 | | /// Initializes a new instance of the <see cref="LocalizedDescriptionAttribute" /> class. |
| | 58 | | /// </summary> |
| | 59 | | /// <param name="resourceKey">The key identifying the localized string in the resource file.</param> |
| | 60 | | /// <example> |
| | 61 | | /// <code language="csharp"> |
| | 62 | | /// [ResourcePath(nameof(TestControl))] |
| | 63 | | /// [TypeDescriptionProvider(typeof(LocalizedTypeDescriptionProvider))] |
| | 64 | | /// public partial class TestControl : UserControl |
| | 65 | | /// { |
| | 66 | | /// [LocalizedCategory("Category_Layout")] |
| | 67 | | /// [LocalizedDescription("Description_Scrollbar")] |
| | 68 | | /// [LocalizedDisplayName("DisplayName_Scrollbar")] |
| | 69 | | /// [Editor(typeof(FlagEnumUIEditor<EnumTextConverter<ScrollBars>>), typeof(UITypeEditor)) |
| | 70 | | /// [TypeConverter(typeof(EnumTextConverter<ScrollBars>))] |
| | 71 | | /// [DefaultValue(ScrollBars.None)] |
| | 72 | | /// [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] |
| | 73 | | /// [EditorBrowsable(EditorBrowsableState.Always)] |
| | 74 | | /// [Bindable(true)] |
| | 75 | | /// public ScrollBars Scrollbars |
| | 76 | | /// { |
| | 77 | | /// get => _Scrollbars; |
| | 78 | | /// set => _Scrollbars = value; |
| | 79 | | /// } |
| | 80 | | /// } |
| | 81 | | /// </code> |
| | 82 | | /// </example> |
| 16 | 83 | | public LocalizedDescriptionAttribute(string resourceKey) : base(resourceKey) |
| 8 | 84 | | { |
| 16 | 85 | | } |
| | 86 | | #endif |
| | 87 | |
|
| | 88 | | /// <summary> |
| | 89 | | /// Gets the <see cref="LocalizedDescriptionAttribute"/> from the specified context. |
| | 90 | | /// </summary> |
| | 91 | | /// <param name="context">The context.</param> |
| | 92 | | /// <returns></returns> |
| | 93 | | public static new LocalizedDescriptionAttribute Get(ITypeDescriptorContext context) => |
| 28 | 94 | | context == null || context.Instance == null || context.PropertyDescriptor == null |
| 28 | 95 | | ? null |
| 28 | 96 | | : Support.Support.GetFirstCustomAttribute<LocalizedDescriptionAttribute>( |
| 28 | 97 | | Support.Support.GetPropertyInfo(context)); |
| | 98 | | } |
| | 99 | | } |