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