-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathValidationExtensions.EntityRule.cs
More file actions
25 lines (23 loc) · 1.85 KB
/
Copy pathValidationExtensions.EntityRule.cs
File metadata and controls
25 lines (23 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
namespace CoreEx.Validation;
public static partial class ValidationExtensions
{
/// <summary>
/// Chains an entity (<see cref="EntityRule{TEntity, TProperty}"/>) validation to the existing <paramref name="rule"/>.
/// </summary>
/// <typeparam name="TEntity">The entity <see cref="Type"/>.</typeparam>
/// <typeparam name="TProperty">The property <see cref="Type"/>.</typeparam>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <param name="with">Extends configuration <see cref="EntityRule{TEntity, TProperty}.With"/>.</param>
public static IPropertyRule<TEntity, TProperty> Entity<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule, Action<EntityRule<TEntity, TProperty>.With> with) where TEntity : class where TProperty : class?
=> Chain(rule, new EntityRule<TEntity, TProperty>(with));
/// <summary>
/// Chains an entity (<see cref="EntityRule{TEntity, TProperty}"/>) validation to the existing <paramref name="rule"/>.
/// </summary>
/// <typeparam name="TEntity">The entity <see cref="Type"/>.</typeparam>
/// <typeparam name="TProperty">The property <see cref="Type"/>.</typeparam>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <param name="validator">The <see cref="IValidatorEx{T}"/>.</param>
/// <remarks>Consider using the <see cref="Entity{TEntity, TProperty}(IPropertyRule{TEntity, TProperty}, Action{EntityRule{TEntity, TProperty}.With})"/> as this provides additional validator options (where applicable).</remarks>
public static IPropertyRule<TEntity, TProperty> Entity<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule, IValidatorEx<TProperty> validator) where TEntity : class where TProperty : class?
=> Entity(rule, w => w.WithValidator(validator));
}