generated from Avanade/avanade-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
248 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/CoreEx | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace CoreEx.Validation | ||
{ | ||
/// <summary> | ||
/// Provides a validation rule for an entity. | ||
/// </summary> | ||
/// <typeparam name="TEntity">The entity <see cref="Type"/>.</typeparam> | ||
public interface IEntityRule<TEntity> where TEntity : class | ||
{ | ||
/// <summary> | ||
/// Validates an entity given a <see cref="ValidationContext{TEntity}"/>. | ||
/// </summary> | ||
/// <param name="context">The <see cref="ValidationContext{TEntity}"/></param> | ||
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param> | ||
Task ValidateAsync(ValidationContext<TEntity> context, CancellationToken cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,48 @@ | ||
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/CoreEx | ||
|
||
using System; | ||
using CoreEx.Localization; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace CoreEx.Validation | ||
{ | ||
/// <summary> | ||
/// Provides a validation rule for a property. | ||
/// Enables a validation rule for an entity property. | ||
/// </summary> | ||
/// <typeparam name="TEntity">The entity <see cref="Type"/>.</typeparam> | ||
public interface IPropertyRule<TEntity> where TEntity : class | ||
public interface IPropertyRule | ||
{ | ||
/// <summary> | ||
/// Validates an entity given a <see cref="ValidationContext{TEntity}"/>. | ||
/// Gets the property name. | ||
/// </summary> | ||
public string Name { get; } | ||
|
||
/// <summary> | ||
/// Gets the JSON property name. | ||
/// </summary> | ||
public string JsonName { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the friendly text name used in validation messages. | ||
/// </summary> | ||
public LText Text { get; set; } | ||
|
||
/// <summary> | ||
/// Executes the validation for the property value. | ||
/// </summary> | ||
/// <param name="context">The <see cref="ValidationContext{TEntity}"/></param> | ||
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param> | ||
Task ValidateAsync(ValidationContext<TEntity> context, CancellationToken cancellationToken); | ||
/// <returns>A <see cref="ValueValidatorResult{TEntity, TProperty}"/>.</returns> | ||
Task<IValidationResult> ValidateAsync(CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Executes the validation for the property value. | ||
/// </summary> | ||
/// <param name="throwOnError">Indicates whether to automatically throw a <see cref="ValidationException"/> where <see cref="IValidationResult.HasErrors"/>.</param> | ||
/// <param name="cancellationToken">>The <see cref="CancellationToken"/>.</param> | ||
/// <returns>A <see cref="ValueValidatorResult{TEntity, TProperty}"/>.</returns> | ||
public async Task<IValidationResult> ValidateAsync(bool throwOnError, CancellationToken cancellationToken = default) | ||
{ | ||
var ir = await ValidateAsync(cancellationToken).ConfigureAwait(false); | ||
return throwOnError ? ir.ThrowOnError() : ir; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.