< Summary

Information
Class: MyNet.Metadata.GeneratedMetadataBootstrapInvoker
Assembly: MyNet.Metadata
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Metadata/GeneratedMetadataBootstrapInvoker.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 47
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
Ensure(...)100%22100%
CreateInvoker(...)100%44100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Metadata/GeneratedMetadataBootstrapInvoker.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="GeneratedMetadataBootstrapInvoker.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections.Concurrent;
 9using System.Reflection;
 10
 11namespace MyNet.Metadata;
 12
 13/// <summary>
 14/// Invokes assembly-generated <c>ObservableMetadataBootstrap.Ensure</c> on first metadata access (lazy configuration).
 15/// </summary>
 16internal static class GeneratedMetadataBootstrapInvoker
 17{
 18    private const string BootstrapTypeFullName = "MyNet.Metadata.Generated.ObservableMetadataBootstrap";
 19
 1220    private static readonly ConcurrentDictionary<Assembly, Action<Type>?> Invokers = new();
 21
 22    /// <summary>
 23    /// Applies generated metadata configuration for <paramref name="type"/> when present in its assembly.
 24    /// </summary>
 25    public static void Ensure(Type type)
 26    {
 1225227        ArgumentNullException.ThrowIfNull(type);
 28
 1225229        var invoker = Invokers.GetOrAdd(type.Assembly, CreateInvoker);
 1225230        invoker?.Invoke(type);
 89731    }
 32
 33    private static Action<Type>? CreateInvoker(Assembly assembly)
 34    {
 3335        var bootstrapType = assembly.GetType(BootstrapTypeFullName, throwOnError: false);
 36
 3337        var ensureMethod = bootstrapType?.GetMethod(
 3338            "Ensure",
 3339            BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic,
 3340            binder: null,
 3341            types: [typeof(Type)],
 3342            modifiers: null);
 43
 3344        return ensureMethod is null ? null : (type => ensureMethod.Invoke(null, [type]));
 45    }
 46}
 47