private static void RequiresNonNull(string property, object obj) { if (obj is null) { throw CheckoutArgumentException.WithMessage($"{property} cannot be null"); } }
private static void RequiresNonBlank(string property, string content) { if (string.IsNullOrWhiteSpace(content)) { throw CheckoutArgumentException.WithMessage($"{property} cannot be blank"); } }
private static void ValidateMultipleParams(object[,] parameters) { if (parameters.Length == 0) { return; } for (var i = 0; i < parameters.GetLength(0); i++) { var property = parameters.GetValue(i, 0); if (!(property is string prop) || string.IsNullOrEmpty(prop)) { throw CheckoutArgumentException.WithMessage("invalid validation key"); } var value = parameters.GetValue(i, 1); if (value is string s) { RequiresNonBlank(prop, s); continue; } RequiresNonNull(prop, value); } }
private static void ValidateSecretKey(Regex pattern, string key) { if (ValidKey(pattern, key)) { return; } throw CheckoutArgumentException.WithMessage("invalid secret key"); }
private static void ValidatePublicKey(Regex pattern, string key) { // public key is not strictly mandatory if (key == null) { return; } if (ValidKey(pattern, key)) { return; } throw CheckoutArgumentException.WithMessage("invalid public key"); }