Is it possible in C# to create a very simple value type for IBAN, BIC (maybe with struct)? That automatically works for features like Json Serialization and EF Core saving?
I would like to use the primitive type in data objects that are converted to Json and also in entities that are stored via EF Core
public class AccountTransaction
{
public Iban RecipientIban { get; set; }
public Bic RecipientBic { get; set; }
}
For instance for EF Core I dont wanna specify some value converter everytime I used those types. Or I dont wanna specify some custom JsonSerializer everytime those types are used in an object. They more or less should work like usual string.
Also the goal would be to achieve some automatic validations on assignment. e.g:
Iban ibanVariable = "ILLEGAL IBAN";
That such calls are leading to errors automatically. (Also on reading from database / deserializing Jsons, etc.)
Is there some simple way I could achieve this? Is there some FromString() thingy or assignment operator at struct that I could overwrite (like operator-overloading)?