skwasjer / IbanNet

C# .NET IBAN validator, parser, builder and generator
Apache License 2.0
126 stars 31 forks source link

IbanBuilder.Build() throw Exception #109

Closed SebastienE closed 1 year ago

SebastienE commented 1 year ago

Hello,

I'm trying to build IBAN from Country, Bank, Branch and Account identifiers.

I'm using last version (5.7.1) with the following code :

var country = new IbanCountry("FR"); IbanBuilder b = new IbanBuilder(); b.WithCountry(country); b.WithBankIdentifier(ValideBankIdentifier); b.WithBranchIdentifier(ValideBranchIdentifier); b.WithBankAccountNumber(ValivdeAccountIdentifier); return b.Build();

And the following exception is throw from BbanBuilder.Build() function.

System.InvalidOperationException: The country 'FR' does not define a BBAN pattern. at IbanNet.Builders.BbanBuilder.Build()

Can you please help me.

Best regards, Sébastien

skwasjer commented 1 year ago

You need to use a IbanCountry instance from the IbanRegistry which contains the pattern/positional information the builder needs.

Iow. smth like:

IbanRegistry.Default.TryGetValue("FR", out IbanCountry country); // Or request IIbanRegistry from DI container
SebastienE commented 1 year ago

It's now good with the country get from IbanRegistry. Thank you.

Regards, Sébastien

skwasjer commented 1 year ago

Good!

I've extended docs as well.