Exemplo n.º 1
0
 // TODO: Put strings into the resources.
 //
 public static MetadataPropertyHandle <TMetadata, TPropertyValue> EnsureAllNotNull <TMetadata, TPropertyValue>(
     this MetadataPropertyHandle <TMetadata, TPropertyValue> hnd)
     where TMetadata : class, IMetadata
     where TPropertyValue : IEnumerable
 {
     //
     hnd.EnsureHandleValid();
     //
     if (hnd.PropertyValue != null)
     {
         try {
             var itemPositionCounter = -1;
             foreach (var item in hnd.PropertyValue)
             {
                 itemPositionCounter++;
                 if (item == null)
                 {
                     throw
                         new MetadataValidationException(
                             message: $"Указано недопустимое значение свойства '{hnd.PropertyName}'.{Environment.NewLine}{FormatXResource(typeof(Array), "CanNotContainNull/NullAt", itemPositionCounter.ToString("d"))}",
                             metadata: hnd.Metadata);
                 }
             }
         }
         catch (Exception firstException) when(!(firstException is MetadataValidationException))
         {
             throw
                 new MetadataValidationException(
                     message: $"Сбой валидации набора свойства '{hnd.PropertyName}'.",
                     metadata: hnd.Metadata,
                     innerException: firstException);
         }
     }
     //
     return(hnd);
 }
Exemplo n.º 2
0
 public static MetadataPropertyHandle <TMetadata, TimeSpan?> EnsureNotLessThan <TMetadata>(
     this MetadataPropertyHandle <TMetadata, TimeSpan?> hnd,
     TimeSpan operand)
     where TMetadata : class, IMetadata
 {
     //
     hnd.EnsureHandleValid();
     //
     if (hnd.PropertyValue.HasValue)
     {
         try {
             hnd
             .PropertyValue
             .Value
             .ArgProp(nameof(hnd.PropertyValue))
             .EnsureNotLessThan(operand);
         }
         catch (ArgumentException firstException) {
             throw hnd.P_CreateMetadataValidationException(firstException);
         }
     }
     //
     return(hnd);
 }
Exemplo n.º 3
0
 // TODO: Put strings into the resources.
 //
 public static MetadataPropertyHandle <TMetadata, TPropertyValue> EnsureValid <TMetadata, TPropertyValue>(this MetadataPropertyHandle <TMetadata, TPropertyValue> hnd, ValueValidator <TPropertyValue> validator)
     where TMetadata : class, IMetadata
 {
     //
     hnd.EnsureHandleValid();
     validator.EnsureNotNull(nameof(validator));
     //
     if (hnd.PropertyValue != null)
     {
         bool   validationResult;
         string validationErrorMessage;
         try {
             validationResult =
                 validator(
                     value: hnd.PropertyValue,
                     errorMessage: out validationErrorMessage);
         }
         catch (Exception firstException) {
             throw
                 new MetadataValidationException(
                     message: $"Ошибка валидации свойства '{hnd.PropertyName}'.",
                     innerException: firstException,
                     metadata: hnd.Metadata);
         }
         if (!validationResult)
         {
             throw
                 new MetadataValidationException(
                     message: $"Валидация свойства '{hnd.PropertyName}' выявила ошибку(-и).{Environment.NewLine}{validationErrorMessage}",
                     metadata: hnd.Metadata);
         }
     }
     //
     return(hnd);
 }