< Summary

Information
Class: MyNet.Observable.ModificationExtensions
Assembly: MyNet.Observable
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Behaviors/Extensions/ModificationExtensions.cs
Tag: 323_28699572109
Line coverage
33%
Covered lines: 3
Uncovered lines: 6
Coverable lines: 9
Total lines: 42
Line coverage: 33.3%
Branch coverage
33%
Covered branches: 4
Total branches: 12
Branch coverage: 33.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IsModified(...)50%9875%
ResetIsModified(...)0%2040%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Behaviors/Extensions/ModificationExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="ModificationExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using MyNet.Observable.Behaviors;
 8
 9#pragma warning disable IDE0130 // Namespace does not match folder structure
 10namespace MyNet.Observable;
 11#pragma warning restore IDE0130 // Namespace does not match folder structure
 12
 13public static class ModificationExtensions
 14{
 15    extension(ObservableObject owner)
 16    {
 17        /// <summary>
 18        /// Determines whether the observable object has been modified since it was last marked as clean. This method ch
 19        /// </summary>
 20        /// <returns>True if the object has been modified; otherwise, false.</returns>
 21        public bool IsModified()
 22        {
 1823            if (owner.Behaviors.TryGet<ModificationTrackingBehavior>(out var tracking))
 024                tracking.EnsureInitialStateAttached();
 25
 1826            return owner is IModificationAware { IsModified: true }
 1827                || (owner.Behaviors.TryGet<IModificationTrackingBehavior>(out var behavior) && behavior.IsModified);
 28        }
 29
 30        /// <summary>
 31        /// Resets the modification state when a <see cref="ModificationTrackingBehavior"/> is registered.
 32        /// </summary>
 33        public void ResetIsModified()
 34        {
 035            if (owner.Behaviors.TryGet<IModificationTrackingBehavior>(out var behavior))
 036                behavior.ResetModified();
 037            else if (owner is IModificationAware modificationAware)
 038                modificationAware.ResetModified();
 039        }
 40    }
 41}
 42