/// <summary> /// Attempts to parse the specified <paramref name="value"/> into an <see cref="Iban"/>. /// </summary> /// <param name="value">The IBAN value to parse.</param> /// <param name="iban">The <see cref="Iban"/> if the <paramref name="value"/> is parsed successfully.</param> /// <param name="validationResult">The validation result.</param> /// <returns>true if the <paramref name="value"/> is parsed successfully, or false otherwise</returns> private static bool TryParse(string value, out Iban iban, out IbanValidationResult validationResult) { iban = null; validationResult = IbanValidationResult.IllegalCharacters; if (value == null) { return(false); } var normalizedValue = Normalize(value); if ((validationResult = Validator.Validate(normalizedValue)) == IbanValidationResult.Valid) { iban = new Iban(normalizedValue.ToUpperInvariant()); return(true); } return(false); }
/// <summary> /// Attempts to parse the specified <paramref name="value"/> into an <see cref="Iban"/>. /// </summary> /// <param name="value">The IBAN value to parse.</param> /// <param name="iban">The <see cref="Iban"/> if the <paramref name="value"/> is parsed successfully.</param> /// <param name="validationResult">The validation result.</param> /// <returns>true if the <paramref name="value"/> is parsed successfully, or false otherwise</returns> private static bool TryParse(string value, out Iban iban, out IbanValidationResult validationResult) { iban = null; validationResult = IbanValidationResult.IllegalCharacters; if (value == null) { return(false); } // Although our validator normalizes too, we can't rely on this fact if other implementations // are provided (like mocks, or maybe faster validators). Thus, to ensure this class correctly // represents the IBAN value, we normalize inline here and take the penalty. string normalizedValue = Normalize(value); ValidationResult result = Validator.Validate(normalizedValue); if (result.Result == IbanValidationResult.Valid) { iban = new Iban(normalizedValue.ToUpperInvariant()); return(true); } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="IbanFormatException"/> class using specified message and validation result. /// </summary> /// <param name="message">The error message.</param> /// <param name="result">The validation result.</param> public IbanFormatException(string message, IbanValidationResult result) : base(message) { Result = result; }