< Summary

Information
Class: MyNet.Metadata.MetadataRegistry
Assembly: MyNet.Metadata
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Metadata/MetadataRegistry.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 7
Uncovered lines: 0
Coverable lines: 7
Total lines: 53
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
.cctor()100%11100%
For()100%11100%
Get(...)100%11100%
GetOrCreate(...)100%11100%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="MetadataRegistry.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.Collections.Generic;
 10
 11namespace MyNet.Metadata;
 12
 13/// <summary>
 14/// Provides a central registry for managing metadata associated with types. This static class allows for the configurat
 15/// </summary>
 16public static class MetadataRegistry
 17{
 1218    private static readonly ConcurrentDictionary<Type, TypeMetadata> Cache = [];
 19
 20    /// <summary>
 21    /// Configures metadata for a specific type. This method takes a generic type parameter T, which represents the type
 22    /// </summary>
 23    /// <typeparam name="T">The type for which metadata is being configured.</typeparam>
 24    /// <returns>A <see cref="MetadataBuilder{T}"/> that can be used to further configure the metadata for the specified
 25    public static MetadataBuilder<T> For<T>()
 26    {
 3027        var metadata = Get(typeof(T));
 3028        return new(metadata);
 29    }
 30
 31    /// <summary>
 32    /// Retrieves the metadata associated with a given type. This method takes a Type object as a parameter and returns 
 33    /// </summary>
 34    /// <param name="type">The type for which metadata is being retrieved.</param>
 35    /// <returns>The <see cref="TypeMetadata"/> associated with the specified type.</returns>
 36    /// <exception cref="KeyNotFoundException">Thrown if there is no metadata associated with the specified type in the 
 37    public static TypeMetadata Get(Type type)
 38    {
 1224639        ArgumentNullException.ThrowIfNull(type);
 40
 1224641        GeneratedMetadataBootstrapInvoker.Ensure(type);
 42
 1224643        return GetOrCreate(type);
 44    }
 45
 46    /// <summary>
 47    /// Retrieves the metadata associated with a given type, or creates a new instance if it does not exist. This method
 48    /// </summary>
 49    /// <param name="type">The type for which metadata is being retrieved or created.</param>
 50    /// <returns>The <see cref="TypeMetadata"/> associated with the specified type.</returns>
 1224651    private static TypeMetadata GetOrCreate(Type type) => Cache.GetOrAdd(type, static _ => new());
 52}
 53