< Summary

Information
Class: SwiftCollections.Observable.SwiftObservableProperty<T>
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Observable/Support/SwiftObservableProperty.cs
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 88
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
.ctor(...)100%11100%
get_Value()100%11100%
set_Value(...)100%22100%
OnPropertyChanged(...)50%22100%

File(s)

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Observable/Support/SwiftObservableProperty.cs

#LineLine coverage
 1using MemoryPack;
 2using System;
 3using System.ComponentModel;
 4using System.Runtime.CompilerServices;
 5using System.Text.Json.Serialization;
 6
 7namespace SwiftCollections.Observable;
 8
 9/// <summary>
 10/// Represents a property of type <typeparamref name="TValue"/> that raises a <see cref="PropertyChanged"/> event when i
 11/// </summary>
 12/// <typeparam name="TValue">The type of the value being observed.</typeparam>
 13[Serializable]
 14[MemoryPackable]
 15public partial class SwiftObservableProperty<TValue> : INotifyPropertyChanged
 16{
 17    #region Fields
 18
 19    internal int Index;
 20
 21    [JsonInclude]
 22    [MemoryPackInclude]
 23    private TValue _value;
 24
 25    #endregion
 26
 27    #region Events
 28
 29    /// <summary>
 30    /// Raised whenever the property's value changes.
 31    /// </summary>
 32    public event PropertyChangedEventHandler? PropertyChanged;
 33
 34    #endregion
 35
 36    #region Constructors
 37
 38    /// <summary>
 39    /// Initializes a new instance of the <see cref="SwiftObservableProperty{TValue}"/> class with the default value of 
 40    /// </summary>
 41    [MemoryPackConstructor]
 20211242    public SwiftObservableProperty() : this(default!) { }
 43
 44    /// <summary>
 45    /// Initializes a new instance of the <see cref="SwiftObservableProperty{TValue}"/> class with the specified initial
 46    /// </summary>
 47    /// <param name="value">The initial value of the property.</param>
 10108148    public SwiftObservableProperty(TValue value)
 49    {
 10108150        _value = value;
 10108151    }
 52
 53    #endregion
 54
 55    #region Properties
 56
 57    /// <summary>
 58    /// Gets or sets the property's value. Raises the <see cref="PropertyChanged"/> event when the value changes.
 59    /// </summary>
 60    [JsonIgnore]
 61    [MemoryPackIgnore]
 62    public TValue Value
 63    {
 10308764        get => _value;
 65        set
 66        {
 103267            if (!Equals(_value, value))
 68            {
 103169                _value = value;
 103170                OnPropertyChanged();
 71            }
 103272        }
 73    }
 74
 75    #endregion
 76
 77    #region Methods
 78
 79    /// <summary>
 80    /// Raises the <see cref="PropertyChanged"/> event with the specified property name.
 81    /// </summary>
 82    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = "")
 83    {
 103184        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
 103185    }
 86
 87    #endregion
 88}