< Summary

Information
Class: MyNet.UI.ViewModels.List.Grouping.GroupingPropertyViewModel<T>
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/List/Grouping/GroupingPropertyViewModel.cs
Tag: 323_28699572109
Line coverage
0%
Covered lines: 0
Uncovered lines: 17
Coverable lines: 17
Total lines: 92
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
set_IsEnabled(...)0%620%
set_ActivatedAt(...)100%210%
Build()100%210%
Matches(...)100%210%
OnIsEnabledChanged()0%620%
ToString()100%210%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/List/Grouping/GroupingPropertyViewModel.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="GroupingPropertyViewModel.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Linq.Expressions;
 9using MyNet.Observable;
 10using MyNet.Observable.Collections.Grouping;
 11using MyNet.Primitives;
 12
 13namespace MyNet.UI.ViewModels.List.Grouping;
 14
 15/// <summary>
 16/// Represents a view model for a grouping property that can be used to configure how a collection is grouped.
 17/// </summary>
 18/// <param name="expression">The expression used to access the property to group by.</param>
 19/// <param name="key">The unique identifier for the grouping property.</param>
 20/// <param name="displayName">The provider for the localized display name.</param>
 21/// <typeparam name="T">The type of the items being grouped.</typeparam>
 022public class GroupingPropertyViewModel<T>(
 023    Expression<Func<T, object?>> expression,
 024    string key,
 025    IObservableValue<string> displayName)
 26    : ObservableObject, IGroupingPropertyViewModel<T>
 27{
 28    /// <summary>
 29    /// Gets the localized display name for this grouping property.
 30    /// </summary>
 031    public IObservableValue<string> DisplayName { get; } = displayName;
 32
 33    /// <summary>
 34    /// Gets the unique identifier for the grouping property. This key is used to identify the grouping property within 
 35    /// </summary>
 036    string IGroupingPropertyViewModel<T>.Key { get; } = key;
 37
 38    /// <summary>
 39    /// Gets the expression that defines the grouping property. This expression is used to determine the value of the pr
 40    /// </summary>
 041    public Expression<Func<T, object?>> Expression { get; } = expression;
 42
 43    /// <summary>
 44    /// Gets or sets a value indicating whether this grouping property is currently enabled/active.
 45    /// When true, this property contributes to the collection's grouping.
 46    /// When false, this property is available but not applied.
 47    /// </summary>
 48    public bool IsEnabled
 49    {
 50        get;
 51        set
 52        {
 053            if (!SetProperty(ref field, value))
 054                return;
 55
 056            OnIsEnabledChanged();
 057        }
 58    }
 59
 060        = true;
 61
 62    /// <summary>
 63    /// Gets the date and time when this grouping property was activated (enabled). This property is null if the groupin
 64    /// </summary>
 65    public DateTime? ActivatedAt
 66    {
 67        get;
 068        private set => SetProperty(ref field, value);
 69    }
 70
 71    /// <summary>
 72    /// Builds the core grouping property based on the current state of the view model. If the grouping property is acti
 73    /// </summary>
 74    /// <returns>An instance of <see cref="IGroupingProperty{T}"/> if the grouping property is active; otherwise, null.<
 075    public IGroupingProperty<T> Build() => new ExpressionGroupingProperty<T>(Expression);
 76
 77    /// <summary>
 78    /// Determines whether the provided grouping property matches the expression of this view model. This method compare
 79    /// </summary>
 80    /// <param name="property">The grouping property to compare with this view model.</param>
 81    /// <returns>True if the expressions match; otherwise, false.</returns>
 082    public bool Matches(IGroupingProperty<T> property) => Expression.IsSimilar(property.ProvideExpression());
 83
 84    /// <summary>
 85    /// Handles changes to the IsEnabled property. When the IsEnabled property changes, this method updates the Activate
 86    /// </summary>
 087    protected virtual void OnIsEnabledChanged() => ActivatedAt = IsEnabled ? DateTime.UtcNow : null;
 88
 89    /// <inheritdoc />
 090    public override string ToString() => DisplayName.Value.OrEmpty();
 91}
 92