Exemplo n.º 1
0
 public static IResult <PositiveInt, NonEmptyString> TryCreate(int?value, NonEmptyString field)
 {
     return(TryCreateInt(value, field, v => TryCreate(v, field)));
 }
Exemplo n.º 2
0
 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)));
 }
Exemplo n.º 3
0
 public static IResult <NonNegativeDecimal, NonEmptyString> TryCreate(decimal?value, NonEmptyString field)
 {
     return(TryCreateInt(value, field, v => TryCreate(v, field)));
 }
Exemplo n.º 4
0
 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)));
 }
Exemplo n.º 5
0
        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>());
        }
Exemplo n.º 6
0
 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())));
 }
Exemplo n.º 7
0
        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());
        }
Exemplo n.º 8
0
 public static IResult <Maybe <NonNegativeDecimal>, NonEmptyString> ToMaybeNonNegativeDecimal(this decimal?value, NonEmptyString field)
 {
     return(value.ToMaybe(field, NonNegativeDecimal.TryCreate));
 }
Exemplo n.º 9
0
 public static IResult <Maybe <NonNegativeInt>, NonEmptyString> ToMaybeNonNegativeInt(this int?value, NonEmptyString field)
 {
     return(value.ToMaybe(field, NonNegativeInt.TryCreate));
 }