< Summary

Information
Class: MyNet.Observable.Behaviors.ObservableBehaviors
Assembly: MyNet.Observable
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Behaviors/ObservableBehaviors.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 98
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Register(...)100%11100%
Unregister(...)100%11100%
TryGet(...)100%11100%
GetAll(...)100%11100%
Get(...)100%11100%
Has(...)100%11100%
GetOrDefault(...)100%11100%
TryExecute(...)100%11100%
Execute(...)100%11100%
TryEvaluate(...)100%11100%
Evaluate(...)100%11100%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="ObservableBehaviors.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Diagnostics.CodeAnalysis;
 9
 10namespace MyNet.Observable.Behaviors;
 11
 12/// <summary>
 13/// Facade for registering and accessing behaviors on an <see cref="ObservableObject"/>.
 14/// </summary>
 15public sealed class ObservableBehaviors
 16{
 17    private readonly BehaviorRegistry _registry;
 18
 193519    internal ObservableBehaviors(BehaviorRegistry registry) => _registry = registry;
 20
 21    /// <summary>
 22    /// Registers or replaces a behavior for the computed key.
 23    /// </summary>
 24    public void Register<T>(T behavior, string? propertyName = null, string? scope = null)
 25        where T : class, IObservableBehavior
 42626        => _registry.Register(behavior, propertyName, scope);
 27
 28    /// <summary>
 29    /// Removes a behavior for the specified key.
 30    /// </summary>
 31    public bool Unregister<T>(string? propertyName = null, string? scope = null)
 32        where T : class, IObservableBehavior
 333        => _registry.Unregister<T>(propertyName, scope);
 34
 35    /// <summary>
 36    /// Tries to get a single behavior matching the optional key parts.
 37    /// </summary>
 38    public bool TryGet<T>([NotNullWhen(true)] out T? behavior, string? propertyName = null, string? scope = null)
 39        where T : class, IObservableBehavior
 13840        => _registry.TryGet(out behavior, propertyName, scope);
 41
 42    /// <summary>
 43    /// Gets all behaviors assignable to <typeparamref name="T"/> matching the optional key parts.
 44    /// </summary>
 45    public T[] GetAll<T>(string? propertyName = null, string? scope = null)
 46        where T : class, IObservableBehavior
 347        => _registry.GetAll<T>(propertyName, scope);
 48
 49    /// <summary>
 50    /// Gets a single behavior or throws when not found or ambiguous.
 51    /// </summary>
 52    public T Get<T>(string? propertyName = null, string? scope = null)
 53        where T : class, IObservableBehavior
 2754        => _registry.Get<T>(propertyName, scope);
 55
 56    /// <summary>
 57    /// Returns whether a single behavior matches the optional key parts.
 58    /// </summary>
 59    public bool Has<T>(string? propertyName = null, string? scope = null)
 60        where T : class, IObservableBehavior
 1561        => _registry.Has<T>(propertyName, scope);
 62
 63    /// <summary>
 64    /// Gets a behavior or <c>null</c> when not found or ambiguous.
 65    /// </summary>
 66    public T? GetOrDefault<T>(string? propertyName = null, string? scope = null)
 67        where T : class, IObservableBehavior
 3368        => _registry.GetOrDefault<T>(propertyName, scope);
 69
 70    /// <summary>
 71    /// Executes an action when a single matching behavior exists.
 72    /// </summary>
 73    public bool TryExecute<T>(Action<T> action, string? propertyName = null, string? scope = null)
 74        where T : class, IObservableBehavior
 375        => _registry.TryExecute(action, propertyName, scope);
 76
 77    /// <summary>
 78    /// Executes an action on a single matching behavior.
 79    /// </summary>
 80    public void Execute<T>(Action<T> action, string? propertyName = null, string? scope = null)
 81        where T : class, IObservableBehavior
 382        => _registry.Execute(action, propertyName, scope);
 83
 84    /// <summary>
 85    /// Evaluates a selector when a single matching behavior exists.
 86    /// </summary>
 87    public bool TryEvaluate<TBehavior, TResult>(Func<TBehavior, TResult> selector, [MaybeNullWhen(false)] out TResult re
 88        where TBehavior : class, IObservableBehavior
 389        => _registry.TryEvaluate(selector, out result, propertyName, scope);
 90
 91    /// <summary>
 92    /// Evaluates a selector on a single matching behavior, or returns <paramref name="defaultValue"/>.
 93    /// </summary>
 94    public TResult Evaluate<TBehavior, TResult>(Func<TBehavior, TResult> selector, TResult defaultValue = default!, stri
 95        where TBehavior : class, IObservableBehavior
 396        => _registry.Evaluate(selector, defaultValue, propertyName, scope);
 97}
 98