| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="MetadataBuilder.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Linq.Expressions; |
| | | 9 | | using MyNet.Primitives; |
| | | 10 | | |
| | | 11 | | namespace MyNet.Metadata; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Provides a builder for constructing metadata for a specific type. This class allows for the fluent configuration of |
| | | 15 | | /// </summary> |
| | | 16 | | /// <typeparam name="T">The type for which metadata is being constructed.</typeparam> |
| | | 17 | | public sealed class MetadataBuilder<T> |
| | | 18 | | { |
| | | 19 | | private readonly TypeMetadata _metadata; |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Initializes a new instance of the <see cref="MetadataBuilder{T}"/> class with the specified type metadata. This |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="metadata">The type metadata that provides access to the overall metadata for the type.</param> |
| | 30 | 25 | | internal MetadataBuilder(TypeMetadata metadata) => _metadata = metadata; |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Specifies the property for which metadata is being configured. This method takes an expression that identifies t |
| | | 29 | | /// </summary> |
| | | 30 | | /// <param name="expression">A lambda expression that identifies the property being configured.</param> |
| | | 31 | | /// <typeparam name="TProperty">The type of the property being configured.</typeparam> |
| | | 32 | | /// <returns>A <see cref="PropertyBuilder{T,TProperty}"/> that can be used to further configure the metadata for the |
| | | 33 | | public PropertyBuilder<T, TProperty> Property<TProperty>(Expression<Func<T, TProperty>> expression) |
| | | 34 | | { |
| | 30 | 35 | | var name = expression.PropertyInfo.Name; |
| | 30 | 36 | | return new(_metadata.GetProperty(name)); |
| | | 37 | | } |
| | | 38 | | } |
| | | 39 | | |