Closed jods4 closed 3 years ago
Are you able to direct me to the schema file(s) that you used? I tried Googling it and could only find this page: https://www.iso20022.org/catalogue-messages/iso-20022-messages-archive
But I don't know which ZIP file to download; there's a lot to filter there.
Sorry, I thought the bug would be generic enough to not require a specific xsd test case. That excerpt comes from code generated out of ISO pain.002.001.03, which is indeed rather large (not a minimal repro). Here's one copy of that schema: https://github.com/sladjan/xsd-camt/blob/master/src/main/resources/schema/pain.002.001.03.xsd
I fixed this in PR #21 with a very small one-line change.
Generated code doesn't correctly take into account optional enums.
See this excerpt generated from ISO 20022 pain.002.001.03.xsd
You can see in the comments that this field is correctly described as
Occurence: optional
andRegex: (... TxSts? ...)
.Yet the property type is a non-nullable Enum
TransactionIndividualStatus3Code
.If you try to read its value, you don't get 0 but an
ArgumentNullException
because it callsEnum.Parse
passingnull
as the string value (fromXTypedServices.ParseValue<string>
).I think a fix would need to:
Enum.Parse
and returnnull
instead.Bonus chatter: I am not sure what runtime you support. If you can go with .net core 2.0 / .net standard 2.1 then there's a handy generic
Enum.Parse<>
that was added.