This package has been discontinued because it never evolved, and the code present in this package does not justify its continuation. It is preferable to implement this code directly in the project if necessary or if you prefer, you can use a good projects like FluentValidation and Flunt.
Utils to help validation of the objects
- .NET 5.0
- .NET 6.0
This package is available through Nuget Packages: https://www.nuget.org/packages/PowerUtils.Validations
Nuget
Install-Package PowerUtils.Validations
.NET CLI
dotnet add package PowerUtils.Validations
var act = new ValidationsContract<int>(5)
.RuleFor("Fake")
.Min(10);
// True
var result = act.Invalid;
public class CountryValidation : ValidationsContract<Country>
{
public CountryValidation(Country source) : base(source)
{
RuleFor(r => r.CountryCode)
.CountryCodeISO2();
}
}
- Properties:
HttpStatusCode StatusCode
;bool Valid
;bool Invalid
;IReadOnlyCollection<ValidationFailure> Notifications
;
- Methods:
IValidationNotifications AddNotification(string property, string errorCode)
;IValidationNotifications AddBadNotification(string property, string errorCode)
;IValidationNotifications AddBadNotification(ValidationFailure notification)
;IValidationNotifications AddBadNotifications(IReadOnlyCollection<ValidationFailure> notifications)
;IValidationNotifications AddBadNotifications(IList<ValidationFailure> notifications)
;IValidationNotifications AddBadNotifications(ICollection<ValidationFailure> notifications)
;IValidationNotifications AddBadNotifications(IEnumerable<ValidationFailure> notifications)
;IValidationNotifications AddBadNotifications(IValidationsContract validations)
;void SetForbiddenStatus(string property)
;void SetNotFoundStatus(string property)
;void SetConflictStatus(string property)
;void SetNotificationStatus(HttpStatusCode statusCode, string property, string errorCode)
;void Clear()
;
- General:
.Gender();
.GenderWithOther();
.ForbiddenValue(options);
- Objects:
.Required();
- Collections:
.Min(min);
.Max(max);
.Range(min, max);
- DateTimes:
.Date(minDate, maxDate);
.MinDateTimeUtcNow();
.MaxDateTimeUtcNow();
- Globalization:
.CountryCodeISO2();
.Latitude();
.Longitude();
- Guids:
.Required();
- Numerics:
.MinZero();
.Min(min);
.Max(max);
.Range(min, max);
- Pagination:
.OrderingDirectionIgnoreCase();
- Strings:
.Required();
.Options(options);
.OptionsIgnoreCase(options);
.MaxLength(maxLength);
.MinLength(minLength);
.Length(minLength, maxLength);
.EmailAddress();
.ForbiddenValue(options);