< Summary - PropertyGridHelpers Code Coverage

Information
Class: PropertyGridHelpers.TypeDescriptionProviders.LocalizedTypeDescriptionProvider
Assembly: PropertyGridHelpers
File(s): c:\agent\_work\9\s\Code\PropertyGridHelpers\TypeDescriptionProviders\LocalizedTypeDescriptionProvider.cs
Tag: PropertyGridHelpers Build_2025.7.15.1_#485
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 132
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
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%
.ctor()--100%11100%
LocalizedTypeDescriptionProvider(...)40----
LocalizedTypeDescriptionProvider()30----
GetTypeDescriptor(...)80----
GetTypeDescriptor(...)--100%11100%
GetTypeDescriptor(...)70----

File(s)

c:\agent\_work\9\s\Code\PropertyGridHelpers\TypeDescriptionProviders\LocalizedTypeDescriptionProvider.cs

#LineLine coverage
 1using PropertyGridHelpers.TypeDescriptors;
 2using System;
 3using System.ComponentModel;
 4
 5namespace PropertyGridHelpers.TypeDescriptionProviders
 6{
 7#if NET8_0_OR_GREATER
 8    /// <summary>
 9    /// Localized Type Description Provider
 10    /// </summary>
 11    /// <param name="type">The type.</param>
 12    /// <seealso cref="TypeDescriptionProvider" />
 13    /// <remarks>
 14    /// Initializes a new instance of the <see cref="LocalizedTypeDescriptionProvider"/> 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&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    public class LocalizedTypeDescriptionProvider(Type type) :
 1640        TypeDescriptionProvider(TypeDescriptor.GetProvider(type))
 41    {
 1642        private readonly TypeDescriptionProvider baseProvider = TypeDescriptor.GetProvider(type);
 43
 44        /// <summary>
 45        /// Initializes a new instance of the <see cref="LocalizedTypeDescriptionProvider"/> class.
 46        /// </summary>
 47        public LocalizedTypeDescriptionProvider()
 1248            : this(typeof(object)) { } // Provide a fallback for dynamic creation
 49#else
 50    /// <summary>
 51    /// Localized Type Description Provider
 52    /// </summary>
 53    /// <seealso cref="TypeDescriptionProvider" />
 54    /// <example>
 55    ///   <code language="csharp">
 56    ///       [ResourcePath(nameof(TestControl))]
 57    ///       [TypeDescriptionProvider(typeof(LocalizedTypeDescriptionProvider))]
 58    ///       public partial class TestControl : UserControl
 59    ///       {
 60    ///           [LocalizedCategory("Category_Layout")]
 61    ///           [LocalizedDescription("Description_Scrollbar")]
 62    ///           [LocalizedDisplayName("DisplayName_Scrollbar")]
 63    ///           [Editor(typeof(FlagEnumUIEditor&lt;EnumTextConverter&lt;ScrollBars&gt;&gt;), typeof(UITypeEditor))]
 64    ///           [TypeConverter(typeof(EnumTextConverter&lt;ScrollBars&gt;))]
 65    ///           [DefaultValue(ScrollBars.None)]
 66    ///           [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
 67    ///           [EditorBrowsable(EditorBrowsableState.Always)]
 68    ///           [Bindable(true)]
 69    ///           public ScrollBars Scrollbars
 70    ///           {
 71    ///               get => _Scrollbars;
 72    ///               set => _Scrollbars = value;
 73    ///           }
 74    ///       }
 75    ///   </code>
 76    /// </example>
 77    public class LocalizedTypeDescriptionProvider :
 78        TypeDescriptionProvider
 79    {
 80        private readonly TypeDescriptionProvider baseProvider;
 81
 82        /// <summary>
 83        /// Initializes a new instance of the <see cref="LocalizedTypeDescriptionProvider"/> class.
 84        /// </summary>
 85        /// <param name="type">The type.</param>
 86        public LocalizedTypeDescriptionProvider(Type type)
 1687            : base(TypeDescriptor.GetProvider(type)) =>
 1688            baseProvider = TypeDescriptor.GetProvider(type);
 89
 90        /// <summary>
 91        /// Initializes a new instance of the <see cref="LocalizedTypeDescriptionProvider"/> class.
 92        /// </summary>
 93        public LocalizedTypeDescriptionProvider()
 1694            : this(typeof(object)) { } // Provide a fallback for dynamic creation
 95#endif
 96
 97        /// <summary>
 98        /// Returns a custom type descriptor for the specified type and instance, enabling localization or
 99        /// other metadata customization.
 100        /// </summary>
 101        /// <param name="objectType">
 102        /// The <see cref="Type"/> of the object for which to retrieve the type descriptor.
 103        /// Cannot be <c>null</c>.
 104        /// </param>
 105        /// <param name="instance">
 106        /// An optional instance of the object whose type descriptor is being requested. May be <c>null</c>.
 107        /// </param>
 108        /// <returns>
 109        /// A custom <see cref="ICustomTypeDescriptor"/> for the specified type, wrapping the base descriptor
 110        /// to provide additional metadata support.
 111        /// </returns>
 112        /// <exception cref="ArgumentNullException">
 113        /// Thrown if <paramref name="objectType"/> is <c>null</c>.
 114        /// </exception>
 115        /// <remarks>
 116        /// This override decorates the standard type descriptor returned by the base provider
 117        /// with a <see cref="LocalizedTypeDescriptor"/> to enable localization of property and event metadata.
 118        /// </remarks>
 119        public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
 16120        {
 121#if NET8_0_OR_GREATER
 8122            ArgumentNullException.ThrowIfNull(objectType);
 123#else
 16124            if (objectType == null)
 16125                throw new ArgumentNullException(nameof(objectType));
 126#endif
 127
 20128            var baseDescriptor = baseProvider.GetTypeDescriptor(objectType, instance);
 20129            return new LocalizedTypeDescriptor(baseDescriptor);
 12130        }
 131    }
 132}