< Summary - PropertyGridHelpers Code Coverage

Information
Class: PropertyGridHelpers.UIEditors.ModalVisualizer<T>
Assembly: PropertyGridHelpers
File(s): c:\agent\_work\9\s\Code\PropertyGridHelpers\UIEditors\ModalVisualizer.cs
Tag: PropertyGridHelpers Build_2025.7.15.1_#485
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 73
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
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

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetEditStyle(...)100%11100%
EditValue(...)100%22100%

File(s)

c:\agent\_work\9\s\Code\PropertyGridHelpers\UIEditors\ModalVisualizer.cs

#LineLine coverage
 1using PropertyGridHelpers.Support;
 2using System;
 3using System.ComponentModel;
 4using System.Drawing.Design;
 5using System.Globalization;
 6using System.Windows.Forms;
 7
 8namespace PropertyGridHelpers.UIEditors
 9{
 10    /// <summary>
 11    /// Provides a reusable, generic modal visualizer for editing a property value within a <see cref="PropertyGrid"/>.
 12    /// This visualizer displays a modal dialog using a form of type <typeparamref name="TForm"/>, allowing
 13    /// rich editing experiences beyond the standard in-place or dropdown editors.
 14    /// </summary>
 15    /// <typeparam name="TForm">
 16    /// A Windows Forms <see cref="Form"/> class that implements <see cref="IValueEditorForm"/> to handle
 17    /// the editing of the property value.
 18    /// </typeparam>
 19    /// <remarks>
 20    /// To use this editor, define a custom form implementing the <see cref="IValueEditorForm"/> interface.
 21    /// The <see cref="IValueEditorForm.EditedValue"/> property is used to push the initial value
 22    /// into the form and retrieve the edited value when the dialog is closed with <see cref="DialogResult.OK"/>.
 23    /// </remarks>
 24    /// <example>
 25    /// <code language="csharp">
 26    /// public class CurrencyEditForm : Form, IValueEditorForm
 27    /// {
 28    ///     public object EditedValue { get; set; }
 29    ///     // implement form logic here
 30    /// }
 31    ///
 32    /// [Editor(typeof(ModalVisualizer&lt;CurrencyEditForm&gt;), typeof(UITypeEditor))]
 33    /// public decimal Amount { get; set; }
 34    /// </code>
 35    /// </example>
 36    /// <seealso cref="UITypeEditor"/>
 37    /// <seealso cref="IValueEditorForm"/>
 38    public class ModalVisualizer<TForm> : UITypeEditor
 39        where TForm : Form, IValueEditorForm, new()
 40    {
 41        /// <inheritdoc/>
 42        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
 843            => UITypeEditorEditStyle.Modal;
 44
 45        /// <summary>
 46        /// Displays the modal editor form to allow the user to edit the property value.
 47        /// </summary>
 48        /// <param name="context">An optional type descriptor context for additional information.</param>
 49        /// <param name="provider">A service provider for editor services.</param>
 50        /// <param name="value">The current value of the property to edit.</param>
 51        /// <returns>
 52        /// The edited value returned from the modal form if the user confirms the edit; otherwise,
 53        /// returns the original <paramref name="value"/>.
 54        /// </returns>
 55        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 856        {
 57#if NET5_0_OR_GREATER
 858            using var form = new TForm();
 59#else
 60            using (var form = new TForm())
 61#endif
 862            {
 863                form.EditedValue = value; // push initial value
 864                form.Context = context; // set context for the form
 865                form.Culture = CultureInfo.CurrentCulture; // set culture if available
 866                if (form.ShowEditor() == DialogResult.OK)
 467                    return form.EditedValue; // get updated value
 68
 469                return value; // no change
 70            }
 871        }
 72    }
 73}