Files
ersatztv/ErsatzTV.Application/Validators/StringValidation.cs
T
Jason DoveandGitHub c02b83d0d6 code cleanup (#743)
* update tools

* run code cleanup

* update dependencies
2022-04-19 17:47:18 -05:00

21 lines
823 B
C#

using System.Linq.Expressions;
using ErsatzTV.Core;
namespace ErsatzTV;
public static partial class Validators
{
public static Func<Expression<Func<T, string>>, Validation<BaseError, string>> NotLongerThan<T>(
this T input,
int maxLength) =>
expression => Optional(expression)
.Map(exp => exp.Compile()(input))
.Where(s => s.Length <= maxLength)
.ToValidation<BaseError>($"[{GetMemberName(expression)}] must not be longer than {maxLength}");
public static Validation<BaseError, string> NotEmpty<T>(this T input, Expression<Func<T, string>> expression) =>
Optional(expression.Compile()(input))
.Where(s => !string.IsNullOrWhiteSpace(s))
.ToValidation<BaseError>($"[{GetMemberName(expression)}] is an empty string");
}