コード例 #1
0
 private static Func <IEnumerable <SpecificationProperty>, IEnumerable <Error> > EnforceMutuallyExclusiveSet()
 {
     return(specProps =>
     {
         var options = specProps
                       .Where(sp => sp.Specification.IsOption())
                       .Where(sp => ((OptionSpecification)sp.Specification).SetName.Length > 0 &&
                              sp.Value.IsJust());
         var groups = options.GroupBy(g => ((OptionSpecification)g.Specification).SetName);
         if (groups.Count() > 1)
         {
             return options.Select(s =>
                                   new MutuallyExclusiveSetError(
                                       NameExtensions.FromOptionSpecification((OptionSpecification)s.Specification)));
         }
         return Enumerable.Empty <Error>();
     });
 }
コード例 #2
0
        MapValues(
            IEnumerable <SpecificationProperty> propertyTuples,
            IEnumerable <KeyValuePair <string, IEnumerable <string> > > options,
            Func <IEnumerable <string>, Type, bool, Maybe <object> > converter,
            StringComparer comparer)
        {
            var sequencesAndErrors = propertyTuples
                                     .Select(pt =>
                                             options.FirstOrDefault(
                                                 s =>
                                                 s.Key.MatchName(((OptionSpecification)pt.Specification).ShortName, ((OptionSpecification)pt.Specification).LongName, comparer))
                                             .ToMaybe()
                                             .Return(sequence =>
                                                     converter(sequence.Value, pt.Property.PropertyType, pt.Specification.TargetType != TargetType.Sequence)
                                                     .Return(converted =>
                                                             Tuple.Create(
                                                                 pt.WithValue(Maybe.Just(converted)),
                                                                 Maybe.Nothing <Error>()),
                                                             Tuple.Create <SpecificationProperty, Maybe <Error> >(
                                                                 pt,
                                                                 Maybe.Just <Error>(new BadFormatConversionError(NameExtensions.FromOptionSpecification((OptionSpecification)pt.Specification))))),
                                                     Tuple.Create(pt, Maybe.Nothing <Error>()))
                                             );

            return(StatePair.Create(
                       sequencesAndErrors.Select(se => se.Item1),
                       sequencesAndErrors.Select(se => se.Item2).OfType <Just <Error> >().Select(se => se.Value)));
        }