< Summary

Information
Class: MyNet.UI.Dialogs.ContentDialogs.DialogResult
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Dialogs/ContentDialogs/DialogResult.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 79
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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Ok()100%11100%
Cancel()100%11100%
Dismiss()100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Dialogs/ContentDialogs/DialogResult.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="DialogResult.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7namespace MyNet.UI.Dialogs.ContentDialogs;
 8
 9/// <summary>
 10/// Provides non-generic factory helpers for the common <see cref="DialogResult{T}"/> of <see cref="bool"/>.
 11/// </summary>
 12public static class DialogResult
 13{
 14    /// <summary>Returns a successful <c>bool</c> result (Value = <see langword="true"/>).</summary>
 3615    public static DialogResult<bool> Ok() => DialogResult<bool>.Success(true);
 16
 17    /// <summary>Returns a cancelled <c>bool</c> result.</summary>
 618    public static DialogResult<bool> Cancel() => DialogResult<bool>.Cancelled();
 19
 20    /// <summary>Returns a dismissed <c>bool</c> result.</summary>
 321    public static DialogResult<bool> Dismiss() => DialogResult<bool>.Dismissed();
 22}
 23
 24/// <summary>
 25/// Represents the result of a dialog operation, indicating whether the dialog was successful, canceled, dismissed, or r
 26/// </summary>
 27/// <typeparam name="T">The type of the value returned by the dialog.</typeparam>
 28public sealed record DialogResult<T>
 29{
 30    /// <summary>
 31    /// Gets the outcome of the dialog operation (Success, Canceled, or Dismissed).
 32    /// </summary>
 33    public DialogOutcome Outcome { get; init; }
 34
 35    /// <summary>
 36    /// Gets a value indicating whether the dialog was confirmed (user clicked OK/Accept).
 37    /// </summary>
 38    public bool IsSuccess => Outcome == DialogOutcome.Success;
 39
 40    /// <summary>
 41    /// Gets a value indicating whether the dialog was explicitly canceled (user clicked Cancel).
 42    /// </summary>
 43    public bool IsCancelled => Outcome == DialogOutcome.Cancelled;
 44
 45    /// <summary>
 46    /// Gets a value indicating whether the dialog was dismissed without an explicit action (e.g. overlay click, Escape 
 47    /// </summary>
 48    public bool IsDismissed => Outcome == DialogOutcome.Dismissed;
 49
 50    /// <summary>
 51    /// Gets the value returned by the dialog. Only meaningful when <see cref="IsSuccess"/> is <see langword="true"/>.
 52    /// </summary>
 53    public T? Value { get; init; }
 54
 55    /// <summary>Creates a successful result carrying <paramref name="value"/>.</summary>
 56    public static DialogResult<T> Success(T value) => new() { Outcome = DialogOutcome.Success, Value = value };
 57
 58    /// <summary>Creates a canceled result (user explicitly canceled).</summary>
 59    public static DialogResult<T> Cancelled() => new() { Outcome = DialogOutcome.Cancelled };
 60
 61    /// <summary>Creates a dismissed result (closed without explicit action).</summary>
 62    public static DialogResult<T> Dismissed() => new() { Outcome = DialogOutcome.Dismissed };
 63}
 64
 65/// <summary>
 66/// Defines the possible outcomes of a dialog operation.
 67/// </summary>
 68public enum DialogOutcome
 69{
 70    /// <summary>The user confirmed the dialog (OK / Accept).</summary>
 71    Success,
 72
 73    /// <summary>The user explicitly canceled the dialog (Cancel button).</summary>
 74    Cancelled,
 75
 76    /// <summary>The dialog was closed without an explicit action (overlay click, Escape, forced close).</summary>
 77    Dismissed
 78}
 79

Methods/Properties

Ok()
Cancel()
Dismiss()