< Summary

Information
Class: NexusLabs.Needlr.MethodInvocation
Assembly: NexusLabs.Needlr
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr/MethodInvocation.cs
Line coverage
100%
Covered lines: 24
Uncovered lines: 0
Coverable lines: 24
Total lines: 81
Line coverage: 100%
Branch coverage
91%
Covered branches: 11
Total branches: 12
Branch coverage: 91.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)90%1010100%
.ctor(...)100%11100%
get_Target()100%11100%
get_Method()100%11100%
get_Arguments()100%11100%
get_GenericArguments()100%11100%
ProceedAsync()100%22100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr/MethodInvocation.cs

#LineLine coverage
 1using System.Reflection;
 2
 3namespace NexusLabs.Needlr;
 4
 5/// <summary>
 6/// Default implementation of <see cref="IMethodInvocation"/> used by generated
 7/// interceptor proxy classes.
 8/// </summary>
 9public sealed class MethodInvocation : IMethodInvocation
 10{
 11    private readonly Func<ValueTask<object?>> _proceed;
 12    private bool _proceeded;
 13
 14    /// <summary>
 15    /// Initializes a new instance of the <see cref="MethodInvocation"/> class.
 16    /// </summary>
 17    /// <param name="target">The target service instance.</param>
 18    /// <param name="method">The method being invoked.</param>
 19    /// <param name="arguments">The arguments passed to the method.</param>
 20    /// <param name="genericArguments">The generic type arguments (empty for non-generic methods).</param>
 21    /// <param name="proceed">
 22    /// A function that invokes the next interceptor or the actual method.
 23    /// </param>
 2524    public MethodInvocation(
 2525        object target,
 2526        MethodInfo method,
 2527        object?[] arguments,
 2528        Type[] genericArguments,
 2529        Func<ValueTask<object?>> proceed)
 30    {
 2531        Target = target ?? throw new ArgumentNullException(nameof(target));
 2432        Method = method ?? throw new ArgumentNullException(nameof(method));
 2333        Arguments = arguments ?? throw new ArgumentNullException(nameof(arguments));
 2234        GenericArguments = genericArguments ?? throw new ArgumentNullException(nameof(genericArguments));
 2235        _proceed = proceed ?? throw new ArgumentNullException(nameof(proceed));
 2136    }
 37
 38    /// <summary>
 39    /// Initializes a new instance of the <see cref="MethodInvocation"/> class
 40    /// for non-generic methods.
 41    /// </summary>
 42    /// <param name="target">The target service instance.</param>
 43    /// <param name="method">The method being invoked.</param>
 44    /// <param name="arguments">The arguments passed to the method.</param>
 45    /// <param name="proceed">
 46    /// A function that invokes the next interceptor or the actual method.
 47    /// </param>
 48    public MethodInvocation(
 49        object target,
 50        MethodInfo method,
 51        object?[] arguments,
 52        Func<ValueTask<object?>> proceed)
 2453        : this(target, method, arguments, Type.EmptyTypes, proceed)
 54    {
 2055    }
 56
 57    /// <inheritdoc />
 158    public object Target { get; }
 59
 60    /// <inheritdoc />
 1161    public MethodInfo Method { get; }
 62
 63    /// <inheritdoc />
 1064    public object?[] Arguments { get; }
 65
 66    /// <inheritdoc />
 467    public Type[] GenericArguments { get; }
 68
 69    /// <inheritdoc />
 70    public ValueTask<object?> ProceedAsync()
 71    {
 1572        if (_proceeded)
 73        {
 174            throw new InvalidOperationException(
 175                "ProceedAsync has already been called on this invocation. " +
 176                "Each interceptor should call ProceedAsync at most once.");
 77        }
 1478        _proceeded = true;
 1479        return _proceed();
 80    }
 81}