< Summary

Information
Class: MyNet.UI.ViewModels.List.Filtering.FilterConditionViewModel<T>
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/List/Filtering/FilterConditionViewModel.cs
Tag: 323_28699572109
Line coverage
60%
Covered lines: 3
Uncovered lines: 2
Coverable lines: 5
Total lines: 62
Line coverage: 60%
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%11100%
set_IsEnabled(...)100%210%
BuildExpression()0%2040%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="FilterConditionViewModel.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;
 10
 11namespace MyNet.UI.ViewModels.List.Filtering;
 12
 13/// <summary>
 14/// Represents a view model for a filter condition that can be applied to items of type T. It includes a key to identify
 15/// </summary>
 16/// <param name="key">The key that identifies this filter condition.</param>
 17/// <param name="isReadOnly">A value indicating whether this filter condition is read-only.</param>
 18/// <typeparam name="T">The type of the items being filtered.</typeparam>
 619public abstract class FilterConditionViewModel<T>(string key, bool isReadOnly = false) : ObservableObject, IFilterCondit
 20{
 21    /// <summary>
 22    /// Gets the key that identifies this filter condition.
 23    /// </summary>
 624    public string Key { get; } = key;
 25
 26    /// <summary>
 27    /// Gets a value indicating whether this filter condition is read-only.
 28    /// </summary>
 629    public bool IsReadOnly { get; } = isReadOnly;
 30
 31    /// <summary>
 32    /// Gets or sets a value indicating whether this filter condition is enabled. When disabled, the condition is ignore
 33    /// </summary>
 34    public bool IsEnabled
 35    {
 36        get;
 037        set => SetProperty(ref field, value);
 38    }
 39
 40    /// <summary>
 41    /// Gets a value indicating whether this filter condition is empty, meaning it has no criteria defined and should no
 42    /// </summary>
 43    public abstract bool IsEmpty { get; }
 44
 45    /// <summary>
 46    /// Builds the expression representing this filter condition. If the condition is empty, it returns an expression th
 47    /// </summary>
 48    /// <returns>An expression representing the filter condition.</returns>
 049    public Expression<Func<T, bool>>? BuildExpression() => IsEmpty || !IsEnabled ? null : BuildExpressionCore();
 50
 51    /// <summary>
 52    /// When overridden in a derived class, builds the specific expression representing this filter condition based on i
 53    /// </summary>
 54    /// <returns>An expression representing the specific filter condition.</returns>
 55    protected abstract Expression<Func<T, bool>> BuildExpressionCore();
 56
 57    /// <summary>
 58    /// Resets the filter condition to its default state. This method should be implemented by derived classes to clear 
 59    /// </summary>
 60    public abstract void Reset();
 61}
 62