< Summary - PropertyGridHelpers Code Coverage

Information
Class: PropertyGridHelpers.Attributes.LocalizedCategoryAttribute
Assembly: PropertyGridHelpers
File(s): c:\agent\_work\9\s\Code\PropertyGridHelpers\Attributes\LocalizedCategoryAttribute.cs
Tag: PropertyGridHelpers Build_2025.7.15.1_#485
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 105
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%
LocalizedCategoryAttribute(...)20----
Get(...)100100%66100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.ComponentModel;
 3
 4namespace PropertyGridHelpers.Attributes
 5{
 6#if NET8_0_OR_GREATER
 7    /// <summary>
 8    /// Attribute for specifying a localized category name for a property or event.
 9    /// </summary>
 10    /// <param name="resourceKey">The key used to retrieve the localized category name from the resource file.</param>
 11    /// <remarks>
 12    /// This attribute allows category names displayed in property grids to be localized
 13    /// by retrieving the category name from a resource file.  If your class has a <see cref="ResourcePathAttribute" />
 14    /// applied to it, the resource key will be looked up in the resource file specified by that attribute.
 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&lt;EnumTextConverter&lt;ScrollBars&gt;&gt;), typeof(UITypeEditor))]
 26    ///           [TypeConverter(typeof(EnumTextConverter&lt;ScrollBars&gt;))]
 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    /// <seealso cref="LocalizedTextAttribute" />
 40    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Method, AllowMultiple = false)
 41    public class LocalizedCategoryAttribute(string resourceKey) :
 3242        LocalizedTextAttribute(resourceKey)
 43    {
 44#else
 45    /// <summary>
 46    /// Attribute for specifying a localized category name for a property or event.
 47    /// </summary>
 48    /// <remarks>
 49    /// This attribute allows category names displayed in property grids to be localized
 50    /// by retrieving the category name from a resource file.  If your class has a <see cref="ResourcePathAttribute" />
 51    /// applied to it, the resource key will be looked up in the resource file specified by that attribute.
 52    /// </remarks>
 53    /// <seealso cref="LocalizedTextAttribute" />
 54    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Method, AllowMultiple = false)
 55    public class LocalizedCategoryAttribute
 56        : LocalizedTextAttribute
 57    {
 58        /// <summary>
 59        /// Initializes a new instance of the <see cref="LocalizedCategoryAttribute" /> class.
 60        /// </summary>
 61        /// <param name="resourceKey">The key used to retrieve the localized category name from the resource file.</para
 62        /// <remarks>
 63        /// The constructor fetches the localized category name using the specified resource key.
 64        /// </remarks>
 65        /// <example>
 66        ///   <code language="csharp">
 67        ///       [ResourcePath(nameof(TestControl))]
 68        ///       [TypeDescriptionProvider(typeof(LocalizedTypeDescriptionProvider))]
 69        ///       public partial class TestControl : UserControl
 70        ///       {
 71        ///           [LocalizedCategory("Category_Layout")]
 72        ///           [LocalizedDescription("Description_Scrollbar")]
 73        ///           [LocalizedDisplayName("DisplayName_Scrollbar")]
 74        ///           [Editor(typeof(FlagEnumUIEditor&lt;EnumTextConverter&lt;ScrollBars&gt;&gt;), typeof(UITypeEditor))
 75        ///           [TypeConverter(typeof(EnumTextConverter&lt;ScrollBars&gt;))]
 76        ///           [DefaultValue(ScrollBars.None)]
 77        ///           [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
 78        ///           [EditorBrowsable(EditorBrowsableState.Always)]
 79        ///           [Bindable(true)]
 80        ///           public ScrollBars Scrollbars
 81        ///           {
 82        ///               get => _Scrollbars;
 83        ///               set => _Scrollbars = value;
 84        ///           }
 85        ///       }
 86        ///   </code>
 87        /// </example>
 88        public LocalizedCategoryAttribute(string resourceKey)
 1689            : base(resourceKey)
 890        {
 1691        }
 92#endif
 93
 94        /// <summary>
 95        /// Gets the <see cref="LocalizedCategoryAttribute"/> from the specified context.
 96        /// </summary>
 97        /// <param name="context">The context.</param>
 98        /// <returns></returns>
 99        public static new LocalizedCategoryAttribute Get(ITypeDescriptorContext context) =>
 28100            context == null || context.Instance == null || context.PropertyDescriptor == null
 28101                ? null
 28102                : Support.Support.GetFirstCustomAttribute<LocalizedCategoryAttribute>(
 28103                    Support.Support.GetPropertyInfo(context));
 104    }
 105}