Skip to content

Instantly share code, notes, and snippets.

@NMillard
Last active February 17, 2021 16:18
Show Gist options
  • Save NMillard/44f90705317cacf27942d06632da912a to your computer and use it in GitHub Desktop.
Save NMillard/44f90705317cacf27942d06632da912a to your computer and use it in GitHub Desktop.
medium article 1
public class Iban {
private readonly string plainIban;
private Iban(string iban) {
if (!Validate(iban)) throw new ArgumentException();
plainIban = iban;
}
private bool Validate(string ibanToValidate) {
// validation (check length, validate check digits and sum, etc.)
return true;
}
public static implicit operator Iban(string iban) {
return new Iban(iban);
}
}
/*
* Client code can use it like below
*/
Iban account = "DK5000400440116243" // <- validation now runs on the string aswell
WithdrawMoney(account, 100);
WithdrawMoney("DK5000400440116243", 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment