コード例 #1
0
 public static ITry <TaxpayerIdentificationNumber, INonEmptyEnumerable <Error> > Create(Country country, string taxpayerNumber)
 {
     return(ObjectValidations.NotNull(country).FlatMap(c => c.Match(
                                                           europeanUnionCountry => EuropeanUnionTaxpayerIdentificationNumber.Create(europeanUnionCountry, taxpayerNumber).Map(n => new TaxpayerIdentificationNumber(n)),
                                                           nonEuropeanUnionCountry => NonEuropeanUnionTaxpayerIdentificationNumber.Create(nonEuropeanUnionCountry, taxpayerNumber).Map(n => new TaxpayerIdentificationNumber(n))
                                                           )));
 }
 public static ITry <NonEuropeanUnionTaxpayerIdentificationNumber, INonEmptyEnumerable <Error> > Create(NonEuropeanUnionCountry country, string taxpayerNumber)
 {
     return(ObjectValidations.NotNull(country).FlatMap(c =>
     {
         var nonEmptyNumber = StringValidations.NonEmpty(taxpayerNumber);
         return nonEmptyNumber.Map(n => new NonEuropeanUnionTaxpayerIdentificationNumber(c, n));
     }));
 }
 public static ITry <EuropeanUnionTaxpayerIdentificationNumber, INonEmptyEnumerable <Error> > Create(EuropeanUnionCountry country, string taxpayerNumber)
 {
     return(ObjectValidations.NotNull(country).FlatMap(c =>
     {
         var validNumber = StringValidations.RegexMatch(taxpayerNumber, country.TaxpayerNumberPattern);
         return validNumber.Map(n => new EuropeanUnionTaxpayerIdentificationNumber(c, n));
     }));
 }
コード例 #4
0
        public static ITry <string, INonEmptyEnumerable <Error> > LengthInRange(string value, int min, int max)
        {
            var nonNullValue = ObjectValidations.NotNull(value);

            return(nonNullValue.FlatMap(v =>
            {
                var validLength = IntValidations.InRange(v.Length, min: min, max: max);
                return validLength.Map(val => v).MapError(e => Error.Create($"Length must be between {min} and {max}"));
            }));
        }