< Summary

Information
Class: MyNet.Observable.Behaviors.EventBehavior<T1, T2>
Assembly: MyNet.Observable
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Behaviors/EventBehavior.cs
Tag: 323_28699572109
Line coverage
93%
Covered lines: 15
Uncovered lines: 1
Coverable lines: 16
Total lines: 61
Line coverage: 93.7%
Branch coverage
80%
Covered branches: 16
Total branches: 20
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%11100%
RaiseEvent(...)80%101088.88%
GetEventReactionProperties()80%1010100%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="EventBehavior.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections.Generic;
 9using MyNet.Metadata;
 10using MyNet.Observable.Behaviors.Metadata.Features;
 11
 12namespace MyNet.Observable.Behaviors;
 13
 14/// <summary>
 15/// Provides functionality to raise events and notify property changes for properties that are associated with a specifi
 16/// </summary>
 17/// <param name="owner">The owner object of this behavior.</param>
 18018public abstract class EventBehavior<TOwner, TEvent>(TOwner owner) : SuspendableBehavior<TOwner>(owner)
 19    where TOwner : ObservableObject
 20    where TEvent : class
 21{
 22    /// <summary>
 23    /// Raises an event of the specified type and notifies property changes for all properties that are associated with 
 24    /// </summary>
 25    /// <param name="evt">The event instance to be raised.</param>
 26    protected void RaiseEvent(TEvent evt)
 27    {
 25828        if (IsDisposed || IsSuspended)
 029            return;
 30
 80431        foreach (var property in GetEventReactionProperties(Owner.GetType()))
 32        {
 14433            Owner.NotifyPropertyChanged(property);
 34        }
 35
 25836        switch (Owner)
 37        {
 38            case IEventAware<TEvent> aware:
 13539                aware.OnEvent(evt);
 13540                break;
 41            case IAsyncEventAware<TEvent> asyncAware:
 342                _ = asyncAware.OnEventAsync(evt);
 43                break;
 44        }
 345    }
 46
 47    private static IEnumerable<string> GetEventReactionProperties(Type ownerType)
 48    {
 25849        var seen = new HashSet<string>(StringComparer.Ordinal);
 50
 184251        for (var current = ownerType; current is not null && typeof(ObservableObject).IsAssignableFrom(current); current
 52        {
 161453            foreach (var property in MetadataRegistry.Get(current).WithFeature<EventReactionFeature>(x => x.Events.Conta
 54            {
 14455                if (seen.Add(property))
 14456                    yield return property;
 57            }
 58        }
 25859    }
 60}
 61