< Summary

Information
Class: MyNet.Collections.ObservableCollectionDecorator<T>
Assembly: MyNet.Collections
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Collections/ObservableCollectionDecorator.cs
Tag: 323_28699572109
Line coverage
79%
Covered lines: 35
Uncovered lines: 9
Coverable lines: 44
Total lines: 197
Line coverage: 79.5%
Branch coverage
80%
Covered branches: 8
Total branches: 10
Branch coverage: 80%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
get_Count()100%11100%
get_IsReadOnly()100%210%
get_Item(...)100%11100%
set_Item(...)100%11100%
Add(...)100%11100%
AddRange(...)100%11100%
Clear()100%210%
Contains(...)100%210%
CopyTo(...)100%11100%
GetEnumerator()100%11100%
IndexOf(...)100%11100%
Insert(...)100%11100%
Move(...)100%11100%
Remove(...)100%11100%
RemoveAt(...)100%210%
Load(...)100%11100%
RemoveRange(...)100%210%
RemoveAll(...)100%11100%
InsertRange(...)100%11100%
SetCapacity(...)100%11100%
get_Capacity()100%210%
System.Collections.IEnumerable.GetEnumerator()100%210%
SuspendCount()100%210%
SuspendNotifications()100%11100%
OnCollectionChanged(...)100%22100%
OnPropertyChanged(...)100%22100%
Dispose(...)50%4485.71%
Dispose()100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Collections/ObservableCollectionDecorator.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="ObservableCollectionDecorator.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections;
 9using System.Collections.Generic;
 10using System.Collections.Specialized;
 11using System.ComponentModel;
 12
 13namespace MyNet.Collections;
 14
 15/// <summary>
 16/// An observable collection that schedules notifications on a specific scheduler (typically UI thread).
 17/// It only owns notification dispatching responsibility.
 18/// </summary>
 19/// <typeparam name="T">The type of items in the collection.</typeparam>
 20public abstract class ObservableCollectionDecorator<T> : IObservableRangeCollection<T>, IDisposable
 21{
 22    /// <summary>
 23    /// Initializes a new instance of the <see cref="ObservableCollectionDecorator{T}"/> class with an existing inner co
 24    /// </summary>
 25    /// <param name="inner">The wrapped collection.</param>
 26    protected ObservableCollectionDecorator(IObservableRangeCollection<T> inner)
 27    {
 5128        Inner = inner ?? throw new ArgumentNullException(nameof(inner));
 29
 4830        Inner.CollectionChanged += OnCollectionChanged;
 4831        Inner.PropertyChanged += OnPropertyChanged;
 4832    }
 33
 34    /// <summary>
 35    /// Gets the inner observable range collection that actually holds the items and raises notifications.
 36    /// </summary>
 37    protected IObservableRangeCollection<T> Inner { get; }
 38
 39    /// <inheritdoc />
 40    public event NotifyCollectionChangedEventHandler? CollectionChanged;
 41
 42    /// <inheritdoc />
 43    public event PropertyChangedEventHandler? PropertyChanged;
 44
 45    /// <inheritdoc />
 346    public virtual int Count => Inner.Count;
 47
 48    /// <inheritdoc />
 049    public virtual bool IsReadOnly => false;
 50
 51    /// <inheritdoc />
 52    public virtual T this[int index]
 53    {
 354        get => Inner[index];
 355        set => Inner[index] = value;
 56    }
 57
 58    /// <inheritdoc />
 1859    public virtual void Add(T item) => Inner.Add(item);
 60
 61    /// <summary>
 62    /// Adds a range of items to the collection.
 63    /// </summary>
 364    public virtual void AddRange(IEnumerable<T> items) => Inner.AddRange(items);
 65
 66    /// <inheritdoc />
 067    public virtual void Clear() => Inner.Clear();
 68
 69    /// <inheritdoc />
 070    public virtual bool Contains(T item) => Inner.Contains(item);
 71
 72    /// <inheritdoc />
 373    public virtual void CopyTo(T[] array, int arrayIndex) => Inner.CopyTo(array, arrayIndex);
 74
 75    /// <inheritdoc />
 1576    public virtual IEnumerator<T> GetEnumerator() => Inner.GetEnumerator();
 77
 78    /// <inheritdoc />
 379    public virtual int IndexOf(T item) => Inner.IndexOf(item);
 80
 81    /// <inheritdoc />
 382    public virtual void Insert(int index, T item) => Inner.Insert(index, item);
 83
 84    /// <summary>
 85    /// Moves an item from one index to another.
 86    /// </summary>
 387    public virtual void Move(int oldIndex, int newIndex) => Inner.Move(oldIndex, newIndex);
 88
 89    /// <inheritdoc />
 390    public virtual bool Remove(T item) => Inner.Remove(item);
 91
 92    /// <inheritdoc />
 093    public virtual void RemoveAt(int index) => Inner.RemoveAt(index);
 94
 95    /// <summary>
 96    /// Replaces the current items with the specified items.
 97    /// </summary>
 398    public virtual void Load(IEnumerable<T> items) => Inner.Load(items);
 99
 100    /// <summary>
 101    /// Removes a range of items from the collection.
 102    /// </summary>
 0103    public virtual void RemoveRange(int index, int count) => Inner.RemoveRange(index, count);
 104
 105    /// <summary>
 106    /// Exposes RemoveAll from the wrapped range collection.
 107    /// </summary>
 3108    public virtual int RemoveAll(Func<T, bool> predicate) => Inner.RemoveAll(predicate);
 109
 110    /// <summary>
 111    /// Exposes InsertRange from the wrapped range collection.
 112    /// </summary>
 3113    public virtual void InsertRange(IEnumerable<T> items, int index) => Inner.InsertRange(items, index);
 114
 115    /// <summary>
 116    /// Exposes capacity configuration from the wrapped range collection.
 117    /// </summary>
 3118    public virtual void SetCapacity(int capacity) => Inner.SetCapacity(capacity);
 119
 120    /// <summary>
 121    /// Gets the current capacity of the wrapped range collection.
 122    /// </summary>
 0123    public virtual int Capacity => Inner.Capacity;
 124
 125    /// <inheritdoc />
 0126    IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
 127
 128    /// <summary>
 129    /// Suspends count notifications, allowing batch updates without triggering count change events until the returned d
 130    /// </summary>
 131    /// <returns>A disposable that, when disposed, resumes count notifications.</returns>
 0132    public virtual IDisposable SuspendCount() => Inner.SuspendCount();
 133
 134    /// <summary>
 135    /// Suspends collection and property change notifications, allowing batch updates without triggering events until th
 136    /// </summary>
 137    /// <returns>A disposable that, when disposed, resumes collection and property change notifications.</returns>
 3138    public virtual IDisposable SuspendNotifications() => Inner.SuspendNotifications();
 139
 140    /// <summary>
 141    /// Handles collection changed events from the inner collection and dispatches them on the specified scheduler.
 142    /// </summary>
 143    /// <param name="sender">The source of the event.</param>
 144    /// <param name="e">The event data.</param>
 145    protected virtual void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
 146    {
 8202147        var collectionChanged = CollectionChanged;
 148
 8202149        collectionChanged?.Invoke(this, e);
 18150    }
 151
 152    /// <summary>
 153    /// Handles property changed events from the inner collection and dispatches them on the specified scheduler.
 154    /// </summary>
 155    /// <param name="sender">The source of the event.</param>
 156    /// <param name="e">The event data.</param>
 157    protected virtual void OnPropertyChanged(object? sender, PropertyChangedEventArgs e)
 158    {
 16341159        var propertyChanged = PropertyChanged;
 160
 16341161        propertyChanged?.Invoke(this, e);
 6162    }
 163
 164    #region IDisposable Support
 165
 166    private bool _isDisposed;
 167
 168    /// <summary>
 169    /// Disposes the object and releases all resources.
 170    /// </summary>
 171    /// <param name="disposing">Indicates whether the method is called from Dispose (true) or from a finalizer (false).<
 172    protected virtual void Dispose(bool disposing)
 173    {
 18174        if (_isDisposed)
 0175            return;
 176
 18177        if (disposing)
 178        {
 18179            Inner.CollectionChanged -= OnCollectionChanged;
 18180            Inner.PropertyChanged -= OnPropertyChanged;
 181        }
 182
 18183        _isDisposed = true;
 18184    }
 185
 186    /// <summary>
 187    /// Disposes the object and releases all resources.
 188    /// </summary>
 189    public void Dispose()
 190    {
 18191        Dispose(true);
 18192        GC.SuppressFinalize(this);
 18193    }
 194
 195    #endregion IDisposable Support
 196}
 197