Пример #1
0
        private static ValidationResult <UserMessage> Map(UserMessageXml userMessage)
        {
            ValidationResult <UserMessage> CreateModel(UserMessageXml validated)
            {
                var transactionsResult = NonEmptyEnumerable <int> .Create(validated.Transactions);

                var propertiesResult =
                    validated.Properties.Traverse(MessageProperty.Create)
                    .SelectMany(ids => ids.AsUnique(p => p.Name));

                return(ValidationResult.Combine(
                           transactionsResult,
                           propertiesResult,
                           (ts, ps) => new UserMessage(ts, ps)));
            }

            return(Spec.Of <UserMessageXml>()
                   .NotNull("cannot create user message from 'null' input")
                   .CreateModel(userMessage, CreateModel));
        }
Пример #2
0
 public static ValidationResult <UserMessage> Create(UserMessageXml userMessage)
 {
     return(Spec.Of <UserMessageXml>()
            .NotNull("cannot create user message from 'null' input")
            .CreateModel(userMessage, Map));
 }