EDI.Net icon indicating copy to clipboard operation
EDI.Net copied to clipboard

Read int as string in model

Open Patrickyp opened this issue 3 years ago • 3 comments

[EdiValue("9(2)", Path = "ISA/0", Description = "ISA01 - Authorization Information Qualifier")]
public int AuthorizationInformationQualifier { get; set; }


[EdiValue("9(2)", Path = "ISA/2", Description = "ISA03 - Security Information Qualifier")]
public string Security_Information_Qualifier { get; set; }

Was looking at X12_850.cs model and noticed that for the picture clause both of these are numeric but 1 reads into a int and other into a string what is the difference when you read into different variable types? Or is this a typo?

Patrickyp avatar Nov 12 '21 22:11 Patrickyp

Hi @Patrickyp thanks for your interest in the library.

What you see is expected behavior. When writing values the format defined is clear that is used as a string format to convert to string .When reading there are two steps

  1. Format metadata used from the picture clause used to parse the value into whatever value type there is defined on the property.
  2. When the binding takes place in your case from string to string there is no conversion that takes place. On the other hand from string to int there is parsing. In the int prop the string value gets truncated if longer than two chars and then passed to a int.TryParse

Similar goes for other data types.

C.

cleftheris avatar Nov 13 '21 09:11 cleftheris

Thanks for clarifying. Right now I need to figure out when reading Edi element if the field was blank or if the formatting was bad e.g. letter in a number only field. I am reading everything as string so that if field blank I would know since it is null and if not I will do my own validation/parsing to check format because I couldn't figure out how to differentiate if a field was blank or bad formatting sometimes since they both came out null.

I don't know if reading everything as string is unnessesary in this case or not.

Patrickyp avatar Nov 20 '21 01:11 Patrickyp

Dont worry about the format spec (pictures) because it will never mess the value so bad when reading. First worry about the binding structure. When deserializing the issue is 99% bad model structure or paths

cleftheris avatar Nov 20 '21 09:11 cleftheris