< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
SetFeature(...)100%11100%
TryGetFeature(...)100%22100%
GetOrCreate()100%22100%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="PropertyMetadata.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.Diagnostics.CodeAnalysis;
 10
 11namespace MyNet.Metadata;
 12
 13/// <summary>
 14/// Represents metadata associated with a property. This class is used to store and manage metadata for a specific prope
 15/// </summary>
 16public sealed class PropertyMetadata
 17{
 37818    private readonly ConcurrentDictionary<Type, object> _features = new();
 19
 20    /// <summary>
 21    /// Sets the feature for the specified type. This method allows you to associate a specific piece of metadata (refer
 22    /// </summary>
 23    /// <param name="feature">The feature to set for the specified type.</param>
 24    /// <typeparam name="TFeature">The type of the feature.</typeparam>
 25    public void SetFeature<TFeature>(TFeature feature)
 5726        where TFeature : class => _features[typeof(TFeature)] = feature;
 27
 28    /// <summary>
 29    /// Tries to get the feature of the specified type. This method checks if there is a feature associated with the pro
 30    /// </summary>
 31    /// <param name="feature">When this method returns, contains the feature of the specified type if it exists; otherwi
 32    /// <typeparam name="TFeature">The type of the feature to retrieve.</typeparam>
 33    /// <returns>true if the feature of the specified type exists; otherwise, false.</returns>
 34    public bool TryGetFeature<TFeature>([NotNullWhen(true)] out TFeature? feature)
 35        where TFeature : class
 36    {
 865537        if (_features.TryGetValue(typeof(TFeature), out var value))
 38        {
 38739            feature = (TFeature)value;
 38740            return true;
 41        }
 42
 826843        feature = null;
 826844        return false;
 45    }
 46
 47    /// <summary>
 48    /// Gets the feature of the specified type, or creates a new instance if it does not exist. This method checks if th
 49    /// </summary>
 50    /// <typeparam name="TFeature">The type of the feature to retrieve or create.</typeparam>
 51    /// <returns>The existing or newly created feature of the specified type.</returns>
 52    public TFeature GetOrCreate<TFeature>()
 53        where TFeature : class, new()
 6054        => (TFeature)_features.GetOrAdd(typeof(TFeature), static _ => new TFeature());
 55}
 56