< Summary - PropertyGridHelpers Code Coverage

Information
Class: PropertyGridHelpers.TypeDescriptors.CustomTypeDescriptorContext
Assembly: PropertyGridHelpers
File(s): c:\agent\_work\9\s\Code\PropertyGridHelpers\TypeDescriptors\CustomTypeDescriptorContext.cs
Tag: PropertyGridHelpers Build_2025.7.15.1_#485
Line coverage
100%
Covered lines: 25
Uncovered lines: 0
Coverable lines: 25
Total lines: 115
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%
CustomTypeDescriptorContext(...)20----
get_Container()--100%11100%
get_Instance()--100%11100%
get_PropertyDescriptor()--100%11100%
GetService(...)10100%11100%
OnComponentChanged()10100%11100%
OnComponentChanged()10----
OnComponentChanging()10100%11100%
Create(...)160----
Create(...)--100%66100%
Create(...)150----

File(s)

c:\agent\_work\9\s\Code\PropertyGridHelpers\TypeDescriptors\CustomTypeDescriptorContext.cs

#LineLine coverage
 1using System;
 2using System.ComponentModel;
 3
 4namespace PropertyGridHelpers.TypeDescriptors
 5{
 6#if NET8_0_OR_GREATER
 7    /// <summary>
 8    /// Provides a custom <see cref="ITypeDescriptorContext"/> implementation
 9    /// for use in property editors, supporting design-time or test-time scenarios.
 10    /// </summary>
 11    /// <param name="propertyDescriptor">
 12    /// The <see cref="PropertyDescriptor"/> describing the property being edited.
 13    /// </param>
 14    /// <param name="instance">
 15    /// The object instance whose property is being edited.
 16    /// </param>
 17    /// <seealso cref="ITypeDescriptorContext"/>
 41618    public partial class CustomTypeDescriptorContext(
 41619            PropertyDescriptor propertyDescriptor,
 41620            object instance) : ITypeDescriptorContext
 21    {
 22#else
 23    /// <summary>
 24    /// Provides a custom <see cref="ITypeDescriptorContext"/> implementation
 25    /// for use in property editors, supporting design-time or test-time scenarios.
 26    /// </summary>
 27    /// <seealso cref="ITypeDescriptorContext"/>
 28    public partial class CustomTypeDescriptorContext : ITypeDescriptorContext
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the <see cref="CustomTypeDescriptorContext"/> class.
 32        /// </summary>
 33        /// <param name="propertyDescriptor">
 34        /// The <see cref="PropertyDescriptor"/> describing the property being edited.
 35        /// </param>
 36        /// <param name="instance">
 37        /// The object instance whose property is being edited.
 38        /// </param>
 1639        public CustomTypeDescriptorContext(
 1640            PropertyDescriptor propertyDescriptor,
 1641            object instance)
 842        {
 1643            PropertyDescriptor = propertyDescriptor;
 1644            Instance = instance;
 1645        }
 46#endif
 47
 48        /// <summary>
 49        /// Gets the container object associated with this context. Always returns <c>null</c>
 50        /// since this implementation does not provide container services.
 51        /// </summary>
 4452        public IContainer Container => null;
 53
 54        /// <summary>
 55        /// Gets the instance whose property is being edited.
 56        /// </summary>
 57        public object Instance
 58        {
 73259            get;
 60#if NET8_0_OR_GREATER
 41661        } = instance;
 62#else
 63        }
 64#endif
 65        /// <summary>
 66        /// Gets the <see cref="PropertyDescriptor"/> describing the property being edited.
 67        /// </summary>
 68        public PropertyDescriptor PropertyDescriptor
 69        {
 139270            get;
 71#if NET8_0_OR_GREATER
 41672        } = propertyDescriptor;
 73#else
 74        }
 75#endif
 76
 77        /// <summary>
 78        /// Gets a service object of the specified type. Always returns <c>null</c>
 79        /// in this implementation, as no services are provided.
 80        /// </summary>
 81        /// <param name="serviceType">The type of service requested.</param>
 82        /// <returns>Always <c>null</c>.</returns>
 4483        public object GetService(Type serviceType) => null; // Provide any required services here.
 84
 85        /// <summary>
 86        /// Called when a component has changed. This implementation does nothing.
 87        /// </summary>
 88        public void OnComponentChanged()
 3689        {
 4490        }
 91
 92        /// <summary>
 93        /// Called before a component is changed. This implementation always returns <c>true</c>,
 94        /// indicating that changes are permitted.
 95        /// </summary>
 96        /// <returns>Always <c>true</c>.</returns>
 4497        public bool OnComponentChanging() => true;
 98
 99        /// <summary>
 100        /// Creates a new <see cref="CustomTypeDescriptorContext"/> for the specified type and property name.
 101        /// </summary>
 102        /// <param name="type">The type whose property is to be described.</param>
 103        /// <param name="propertyName">The name of the property to describe.</param>
 104        /// <returns>
 105        /// An instance of <see cref="CustomTypeDescriptorContext"/> representing the requested type and property.
 106        /// </returns>
 107        public static ITypeDescriptorContext Create(Type type, string propertyName)
 104108        {
 112109            var instance = type == null ? null : Activator.CreateInstance(type);
 112110            var propertyDescriptor = type == null || string.IsNullOrEmpty(propertyName) ?
 112111                                        null : TypeDescriptor.GetProperties(type)[propertyName];
 112112            return new CustomTypeDescriptorContext(propertyDescriptor, instance);
 104113        }
 114    }
 115}