| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="PropertyBuilder.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | |
| | | 9 | | namespace MyNet.Metadata; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Provides a builder for configuring metadata for a specific property of a type. This class allows for the fluent conf |
| | | 13 | | /// </summary> |
| | | 14 | | /// <param name="metadata">The metadata associated with the property being configured.</param> |
| | | 15 | | /// <typeparam name="T">The type that owns the property being configured.</typeparam> |
| | | 16 | | /// <typeparam name="TProperty">The type of the property being configured.</typeparam> |
| | | 17 | | public sealed class PropertyBuilder<T, TProperty>(PropertyMetadata metadata) |
| | | 18 | | { |
| | | 19 | | /// <summary> |
| | | 20 | | /// Gets the underlying property metadata being configured. |
| | | 21 | | /// </summary> |
| | 39 | 22 | | public PropertyMetadata Metadata => metadata; |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Specifies a feature or attribute that should be associated with the property being configured. This method allow |
| | | 26 | | /// </summary> |
| | | 27 | | /// <param name="configure">An action that configures the feature for the property.</param> |
| | | 28 | | /// <typeparam name="TFeature">The type of the feature to associate with the property.</typeparam> |
| | | 29 | | /// <returns>The current <see cref="PropertyBuilder{T, TProperty}"/> instance for fluent configuration.</returns> |
| | | 30 | | public PropertyBuilder<T, TProperty> Feature<TFeature>(Action<TFeature> configure) |
| | | 31 | | where TFeature : class, new() |
| | | 32 | | { |
| | 3 | 33 | | var feature = metadata.GetOrCreate<TFeature>(); |
| | 3 | 34 | | configure(feature); |
| | 3 | 35 | | return this; |
| | | 36 | | } |
| | | 37 | | } |
| | | 38 | | |