mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
948 B
24 lines
948 B
using System; |
|
using System.Linq.Expressions; |
|
using ErsatzTV.Core; |
|
using LanguageExt; |
|
using static LanguageExt.Prelude; |
|
|
|
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"); |
|
} |
|
}
|
|
|