< Summary - PropertyGridHelpers Code Coverage

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

File(s)

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

#LineLine coverage
 1using System;
 2using System.ComponentModel;
 3
 4namespace PropertyGridHelpers.Attributes
 5{
 6#if NET8_0_OR_GREATER
 7    /// <summary>
 8    /// Specifies a property containing the file extension to use when resolving
 9    /// resource names for an <see cref="UIEditors.ImageTextUIEditor"/>.
 10    /// </summary>
 11    /// <param name="propertyName">
 12    /// The name of the property on the same object that provides the file extension value.
 13    /// </param>
 14    /// <remarks>
 15    /// This attribute is intended for scenarios where an image resource is dynamically
 16    /// constructed from an enum value plus a file extension. It works together with
 17    /// <see cref="ResourcePathAttribute"/>, <see cref="DynamicPathSourceAttribute"/>, and
 18    /// <see cref="EnumImageAttribute"/> to build a complete resource path for images or icons.
 19    /// </remarks>
 20    /// <seealso cref="Attribute"/>
 21    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
 6822    public class FileExtensionAttribute(string propertyName) : Attribute
 23#else
 24    /// <summary>
 25    /// Specifies a property containing the file extension to use when resolving
 26    /// resource names for an <see cref="UIEditors.ImageTextUIEditor"/>.
 27    /// </summary>
 28    /// <remarks>
 29    /// This attribute is intended for scenarios where an image resource is dynamically
 30    /// constructed from an enum value plus a file extension. It works together with
 31    /// <see cref="ResourcePathAttribute"/>, <see cref="DynamicPathSourceAttribute"/>, and
 32    /// <see cref="EnumImageAttribute"/> to build a complete resource path for images or icons.
 33    /// </remarks>
 34    /// <seealso cref="Attribute"/>
 35    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
 36    public class FileExtensionAttribute : Attribute
 37#endif
 38    {
 39        /// <summary>
 40        /// Gets the name of the property containing the file extension.
 41        /// </summary>
 42        /// <value>
 43        /// The name of the property on the target object that will be used to determine
 44        /// the file extension when building the resource path.
 45        /// </value>
 46        public string PropertyName
 47        {
 4448            get;
 49#if NET8_0_OR_GREATER
 6850        } = propertyName;
 51#else
 52        }
 53
 54        /// <summary>
 55        /// Gets the name of the property containing the file extension.
 56        /// </summary>
 57        /// <value>
 58        /// The name of the property on the target object that will be used to determine
 59        /// the file extension when building the resource path.
 60        /// </value>
 1661        public FileExtensionAttribute(string propertyName) => PropertyName = propertyName;
 62#endif
 63
 64        /// <summary>
 65        /// Checks whether a <see cref="FileExtensionAttribute"/> exists on the current
 66        /// property within the given context.
 67        /// </summary>
 68        /// <param name="context">The type descriptor context.</param>
 69        /// <returns>
 70        /// <c>true</c> if the attribute is applied; otherwise, <c>false</c>.
 71        /// </returns>
 72        public static bool Exists(ITypeDescriptorContext context) =>
 2473            Get(context) != null;
 74
 75        /// <summary>
 76        /// Retrieves the <see cref="FileExtensionAttribute"/> applied to the property
 77        /// described by the given context, if any.
 78        /// </summary>
 79        /// <param name="context">The type descriptor context.</param>
 80        /// <returns>
 81        /// The <see cref="FileExtensionAttribute"/>, or <c>null</c> if none is applied.
 82        /// </returns>
 83        public static FileExtensionAttribute Get(ITypeDescriptorContext context) =>
 6884            context == null || context.Instance == null || context.PropertyDescriptor == null
 6885                ? null
 6886                : Support.Support.GetFirstCustomAttribute<FileExtensionAttribute>(
 6887                    Support.Support.GetPropertyInfo(context));
 88    }
 89}