public static void RequireValidated(object parameterValue, string parameterName, string customMessage = null)
 {
     if (parameterValue == null)
     {
         return;
     }
     if (!(parameterValue is IValidatable validatable))
     {
         return;
     }
     try
     {
         validatable.Validate(null, parameterValue.GetType().Name);
     }
     catch (ValidationException e)
     {
         GenericBase <TException> .ThrowException($"ContractViolation: Validation failed for {parameterName} ({e.Message}).");
     }
 }
Beispiel #2
0
 public static void IsValidated(object value, string customMessage = null)
 {
     if (value == null)
     {
         return;
     }
     if (!(value is IValidatable validatable))
     {
         return;
     }
     try
     {
         validatable.Validate(null, value.GetType().Name);
     }
     catch (ValidationException e)
     {
         GenericBase <TException> .ThrowException($"Expected validation to pass ({e.Message}).");
     }
 }
 public static void Fail(string message)
 {
     InternalContract.RequireNotNullOrWhiteSpace(message, nameof(message));
     GenericBase <TException> .ThrowException(message);
 }