Beispiel #1
0
 private static Func <IEnumerable <SpecificationProperty>, IEnumerable <Maybe <Error> > > EnforceRequired()
 {
     return(specProps =>
     {
         var options = specProps.Where(sp => sp.Value.IsNothing() && sp.Specification.Required);
         if (options.Any())
         {
             return options.Select(s => Maybe.Just <Error>(new MissingRequiredOptionError(
                                                               NameInfo.FromSpecification(s.Specification))));
         }
         return Enumerable.Empty <Nothing <Error> >();
     });
 }
Beispiel #2
0
 private static Func <IEnumerable <SpecificationProperty>, IEnumerable <Maybe <Error> > > EnforceRange()
 {
     return(specProps =>
     {
         var options = specProps.Where(
             sp => sp.Specification.ConversionType.ToDescriptor() == DescriptorType.Sequence &&
             sp.Value.IsJust() &&
             ((Array)sp.Value.FromJust()).Length < sp.Specification.Min);
         if (options.Any())
         {
             return options.Select(s => Maybe.Just <Error>(new SequenceOutOfRangeError(
                                                               NameInfo.FromSpecification(s.Specification))));
         }
         return Enumerable.Empty <Nothing <Error> >();
     });
 }
Beispiel #3
0
        private static Func <IEnumerable <SpecificationProperty>, IEnumerable <Maybe <Error> > > EnforceRequired()
        {
            return(specProps =>
            {
                List <string> setsWithTrue =
                    specProps.Where(sp => sp.Specification.IsOption() && sp.Value.IsJust() && sp.Specification.Required)
                    .Select(x => ((OptionSpecification)x.Specification).SetName).ToList();

                var requiredButEmpty =
                    specProps.Where(sp => sp.Value.IsNothing() &&
                                    sp.Specification.Required &&
                                    !setsWithTrue.Contains(((OptionSpecification)sp.Specification).SetName)).ToList();
                if (requiredButEmpty.Any())
                {
                    return requiredButEmpty.Select(s => Maybe.Just <Error>(new MissingRequiredOptionError(
                                                                               NameInfo.FromSpecification(s.Specification))));
                }
                return Enumerable.Empty <Nothing <Error> >();
            });
        }