< 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: 95
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
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(...)100%22100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// SwiftObservableProperty.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024–present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8using MemoryPack;
 9using System;
 10using System.ComponentModel;
 11using System.Runtime.CompilerServices;
 12using System.Text.Json.Serialization;
 13
 14namespace SwiftCollections.Observable;
 15
 16/// <summary>
 17/// Represents a property of type <typeparamref name="TValue"/> that raises a <see cref="PropertyChanged"/> event when i
 18/// </summary>
 19/// <typeparam name="TValue">The type of the value being observed.</typeparam>
 20[Serializable]
 21[MemoryPackable]
 22public partial class SwiftObservableProperty<TValue> : INotifyPropertyChanged
 23{
 24    #region Fields
 25
 26    internal int Index;
 27
 28    [JsonInclude]
 29    [MemoryPackInclude]
 30    private TValue _value;
 31
 32    #endregion
 33
 34    #region Events
 35
 36    /// <summary>
 37    /// Raised whenever the property's value changes.
 38    /// </summary>
 39    public event PropertyChangedEventHandler? PropertyChanged;
 40
 41    #endregion
 42
 43    #region Constructors
 44
 45    /// <summary>
 46    /// Initializes a new instance of the <see cref="SwiftObservableProperty{TValue}"/> class with the default value of 
 47    /// </summary>
 48    [MemoryPackConstructor]
 20211249    public SwiftObservableProperty() : this(default!) { }
 50
 51    /// <summary>
 52    /// Initializes a new instance of the <see cref="SwiftObservableProperty{TValue}"/> class with the specified initial
 53    /// </summary>
 54    /// <param name="value">The initial value of the property.</param>
 10108255    public SwiftObservableProperty(TValue value)
 56    {
 10108257        _value = value;
 10108258    }
 59
 60    #endregion
 61
 62    #region Properties
 63
 64    /// <summary>
 65    /// Gets or sets the property's value. Raises the <see cref="PropertyChanged"/> event when the value changes.
 66    /// </summary>
 67    [JsonIgnore]
 68    [MemoryPackIgnore]
 69    public TValue Value
 70    {
 10308871        get => _value;
 72        set
 73        {
 103374            if (!Equals(_value, value))
 75            {
 103276                _value = value;
 103277                OnPropertyChanged();
 78            }
 103379        }
 80    }
 81
 82    #endregion
 83
 84    #region Methods
 85
 86    /// <summary>
 87    /// Raises the <see cref="PropertyChanged"/> event with the specified property name.
 88    /// </summary>
 89    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = "")
 90    {
 103291        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
 103192    }
 93
 94    #endregion
 95}