| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="MetadataApplicators.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using MyNet.Metadata; |
| | | 8 | | using MyNet.Observable.Behaviors.Metadata.Features; |
| | | 9 | | using MyNet.Observable.Behaviors.Metadata.Features.Events; |
| | | 10 | | |
| | | 11 | | namespace MyNet.Observable.Behaviors.Metadata; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Applies observable metadata features to <see cref="PropertyMetadata"/> instances. |
| | | 15 | | /// Used by the metadata source generator and by fluent configuration extensions. |
| | | 16 | | /// </summary> |
| | | 17 | | public static class MetadataApplicators |
| | | 18 | | { |
| | | 19 | | /// <summary> |
| | | 20 | | /// Configures the property to ignore modification tracking. |
| | | 21 | | /// </summary> |
| | | 22 | | public static void ApplyIgnoreModificationTracking(PropertyMetadata metadata) |
| | 15 | 23 | | => metadata.SetFeature(new ModificationTrackingFeature { Ignore = true }); |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Configures the property to refresh when the application culture changes. |
| | | 27 | | /// </summary> |
| | | 28 | | public static void ApplyUpdateOnCultureChanged(PropertyMetadata metadata) |
| | 36 | 29 | | => metadata.GetOrCreate<EventReactionFeature>().Events.Add(typeof(CultureChangedEvent)); |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Configures the property to refresh when the application time zone changes. |
| | | 33 | | /// </summary> |
| | | 34 | | public static void ApplyUpdateOnTimeZoneChanged(PropertyMetadata metadata) |
| | 9 | 35 | | => metadata.GetOrCreate<EventReactionFeature>().Events.Add(typeof(TimeZoneChangedEvent)); |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Adds a validation dependency on another property. |
| | | 39 | | /// </summary> |
| | | 40 | | public static void ApplyAlsoValidate(PropertyMetadata metadata, string dependentPropertyName) |
| | 9 | 41 | | => metadata.GetOrCreate<ValidationDependencyFeature>().Dependents.Add(dependentPropertyName); |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Configures property-changed forwarding from a wrapper property to the owner. |
| | | 45 | | /// </summary> |
| | | 46 | | public static void ApplyForwardProperty(PropertyMetadata metadata, bool concatenatePropertyName = true) |
| | 33 | 47 | | => metadata.SetFeature(new PropertyChangedForwardingFeature { ConcatenatePropertyName = concatenatePropertyName |
| | | 48 | | } |
| | | 49 | | |