< Summary

Information
Class: MyNet.Observable.FeaturesExtensions
Assembly: MyNet.Observable
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Behaviors/Extensions/FeaturesExtensions.cs
Tag: 323_28699572109
Line coverage
87%
Covered lines: 21
Uncovered lines: 3
Coverable lines: 24
Total lines: 121
Line coverage: 87.5%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
UpdateOnCultureChanged(...)100%22100%
UpdateOnTimeZoneChanged(...)0%620%
IgnoreModificationTracking(...)100%22100%
ReactTo(...)100%11100%
UpdateOnCultureChanged(...)100%11100%
UpdateOnTimeZoneChanged(...)100%11100%
IgnoreModificationTracking(...)100%11100%
ForwardPropertyChanged(...)100%11100%
Validates(...)100%22100%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="FeaturesExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using MyNet.Metadata;
 9using MyNet.Observable.Behaviors.Metadata;
 10using MyNet.Observable.Behaviors.Metadata.Features;
 11
 12#pragma warning disable IDE0130 // Namespace does not match folder structure
 13namespace MyNet.Observable;
 14#pragma warning restore IDE0130 // Namespace does not match folder structure
 15
 16/// <summary>
 17/// Fluent configuration extensions for observable metadata.
 18/// Authoring API: <see cref="MetadataRegistry.For{T}"/> → <see cref="PropertyBuilder{T,TProperty}"/>.
 19/// Batch API: <see cref="TypeMetadata"/> extension methods for multiple property names.
 20/// </summary>
 21public static class FeaturesExtensions
 22{
 23    extension(TypeMetadata metadata)
 24    {
 25        /// <summary>
 26        /// Configures the specified properties to refresh when the application culture changes.
 27        /// </summary>
 28        public TypeMetadata UpdateOnCultureChanged(params string[] propertyNames)
 29        {
 1830            foreach (var propertyName in propertyNames)
 631                MetadataApplicators.ApplyUpdateOnCultureChanged(metadata.GetProperty(propertyName));
 32
 333            return metadata;
 34        }
 35
 36        /// <summary>
 37        /// Configures the specified properties to refresh when the application time zone changes.
 38        /// </summary>
 39        public TypeMetadata UpdateOnTimeZoneChanged(params string[] propertyNames)
 40        {
 041            foreach (var propertyName in propertyNames)
 042                MetadataApplicators.ApplyUpdateOnTimeZoneChanged(metadata.GetProperty(propertyName));
 43
 044            return metadata;
 45        }
 46
 47        /// <summary>
 48        /// Configures the specified properties to ignore modification tracking.
 49        /// </summary>
 50        public TypeMetadata IgnoreModificationTracking(params string[] propertyNames)
 51        {
 1252            foreach (var propertyName in propertyNames)
 353                MetadataApplicators.ApplyIgnoreModificationTracking(metadata.GetProperty(propertyName));
 54
 355            return metadata;
 56        }
 57    }
 58
 59    extension<T, TProperty>(PropertyBuilder<T, TProperty> builder)
 60    {
 61        /// <summary>
 62        /// Configures the property to react to changes of the specified event type.
 63        /// Prefer <see cref="UpdateOnCultureChanged"/> / <see cref="UpdateOnTimeZoneChanged"/> for built-in events.
 64        /// </summary>
 65        public PropertyBuilder<T, TProperty> ReactTo(Type eventType)
 66        {
 367            ArgumentNullException.ThrowIfNull(eventType);
 368            var feature = builder.Metadata.GetOrCreate<EventReactionFeature>();
 369            feature.Events.Add(eventType);
 370            return builder;
 71        }
 72
 73        /// <summary>
 74        /// Configures the property to update when the culture changes.
 75        /// </summary>
 76        public PropertyBuilder<T, TProperty> UpdateOnCultureChanged()
 77        {
 978            MetadataApplicators.ApplyUpdateOnCultureChanged(builder.Metadata);
 979            return builder;
 80        }
 81
 82        /// <summary>
 83        /// Configures the property to update when the time zone changes.
 84        /// </summary>
 85        public PropertyBuilder<T, TProperty> UpdateOnTimeZoneChanged()
 86        {
 687            MetadataApplicators.ApplyUpdateOnTimeZoneChanged(builder.Metadata);
 688            return builder;
 89        }
 90
 91        /// <summary>
 92        /// Configures the property to ignore modification tracking.
 93        /// </summary>
 94        public PropertyBuilder<T, TProperty> IgnoreModificationTracking()
 95        {
 996            MetadataApplicators.ApplyIgnoreModificationTracking(builder.Metadata);
 997            return builder;
 98        }
 99
 100        /// <summary>
 101        /// Configures the property to relay child property-changed notifications to the owner.
 102        /// </summary>
 103        public PropertyBuilder<T, TProperty> ForwardPropertyChanged(bool concatenatePropertyName = true)
 104        {
 3105            MetadataApplicators.ApplyForwardProperty(builder.Metadata, concatenatePropertyName);
 3106            return builder;
 107        }
 108
 109        /// <summary>
 110        /// Configures the property to validate when the specified dependent properties change.
 111        /// </summary>
 112        public PropertyBuilder<T, TProperty> Validates(params string[] dependentProperties)
 113        {
 24114            foreach (var dependentProperty in dependentProperties)
 6115                MetadataApplicators.ApplyAlsoValidate(builder.Metadata, dependentProperty);
 116
 6117            return builder;
 118        }
 119    }
 120}
 121