< Summary - PropertyGridHelpers Code Coverage

Information
Class: PropertyGridHelpers.Attributes.LocalizedDescriptionAttribute
Assembly: PropertyGridHelpers
File(s): c:\agent\_work\9\s\Code\PropertyGridHelpers\Attributes\LocalizedDescriptionAttribute.cs
Tag: PropertyGridHelpers Build_2025.7.15.1_#485
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 99
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBlocks covered Blocks not covered Branch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)--100%11100%
LocalizedDescriptionAttribute(...)20----
Get(...)100100%66100%

File(s)

c:\agent\_work\9\s\Code\PropertyGridHelpers\Attributes\LocalizedDescriptionAttribute.cs

#LineLine coverage
 1using System;
 2using System.ComponentModel;
 3
 4namespace 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&lt;EnumTextConverter&lt;ScrollBars&gt;&gt;), typeof(UITypeEditor))]
 28    ///           [TypeConverter(typeof(EnumTextConverter&lt;ScrollBars&gt;))]
 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)
 2442    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&lt;EnumTextConverter&lt;ScrollBars&gt;&gt;), typeof(UITypeEditor))
 70        ///           [TypeConverter(typeof(EnumTextConverter&lt;ScrollBars&gt;))]
 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>
 1683        public LocalizedDescriptionAttribute(string resourceKey) : base(resourceKey)
 884        {
 1685        }
 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) =>
 2894            context == null || context.Instance == null || context.PropertyDescriptor == null
 2895                ? null
 2896                : Support.Support.GetFirstCustomAttribute<LocalizedDescriptionAttribute>(
 2897                    Support.Support.GetPropertyInfo(context));
 98    }
 99}