public static IResult <PositiveInt, NonEmptyString> TryCreate(int?value, NonEmptyString field) { return(TryCreateInt(value, field, v => TryCreate(v, field))); }
public static IResult <PositiveInt, NonEmptyString> TryCreate(int value, NonEmptyString field) { return(TryCreateInt(value, (NonEmptyString)(field + " can't be less or equal to zero"), v => v > 0, v => new PositiveInt(v))); }
public static IResult <NonNegativeDecimal, NonEmptyString> TryCreate(decimal?value, NonEmptyString field) { return(TryCreateInt(value, field, v => TryCreate(v, field))); }
public static IResult <NonNegativeDecimal, NonEmptyString> TryCreate(decimal value, NonEmptyString field) { return(TryCreateInt(value, (NonEmptyString)(field + " can't be lower than zero"), v => v >= 0, v => new NonNegativeDecimal(v))); }
public static IResult <Guid, NonEmptyString> TryParseToGuid(this string guidString, NonEmptyString fieldName) { Guid guid; var result = Guid.TryParse(guidString, out guid); return(result ? guid.GetOkMessage() : ((NonEmptyString)("Unable to convert " + fieldName + " to valid guid")).GetFailResult <Guid>()); }
public static IResult <NonEmptyLowerCaseString, NonEmptyString> TryCreate(string value, NonEmptyString field) { return(TryCreateInt(value, (NonEmptyString)(field + "can't be empty"), s => s != string.Empty, s => new NonEmptyLowerCaseString(s.ToLower()))); }
public static IResult <Maybe <TResult>, NonEmptyString> ToMaybe <TResult, TIn>(this TIn?value, NonEmptyString field, Func <TIn?, NonEmptyString, IResult <TResult, NonEmptyString> > creatorFunc) where TResult : class where TIn : struct { if (value == null) { return(((Maybe <TResult>)null).GetOkMessage()); } var result = creatorFunc(value, field); return(result.IsFailure ? result.Error.GetFailResult <Maybe <TResult> >() : ((Maybe <TResult>)result.Value).GetOkMessage()); }
public static IResult <Maybe <NonNegativeDecimal>, NonEmptyString> ToMaybeNonNegativeDecimal(this decimal?value, NonEmptyString field) { return(value.ToMaybe(field, NonNegativeDecimal.TryCreate)); }
public static IResult <Maybe <NonNegativeInt>, NonEmptyString> ToMaybeNonNegativeInt(this int?value, NonEmptyString field) { return(value.ToMaybe(field, NonNegativeInt.TryCreate)); }