indice-co / EDI.Net

EDI Serializer/Deserializer. Supports EDIFact, X12 and TRADACOMS formats
MIT License
447 stars 170 forks source link

Question for path #243

Open AlittleBird2023 opened 1 year ago

AlittleBird2023 commented 1 year ago

Hello,

I am a newbie to Indice.EDI. Could anyone please help explain to me what's the difference in the path between "DTM/0" and "DTM/0/0"? How to use the "path" well? Sorry for my stupid question!

cleftheris commented 1 year ago

Hi @AlittleBird2023 and thanks for your interest in EDI.Net.

The path is interpreted contextually. This means that when paired with an EdiElement attribute it is interpreted as one level path and on an EdiValue attribute it is always treated as a two level path (element index, component index). That said, when the zero index is omitted it is considered implied so in an EdiValue

Check these examples for the EdiValue

Accordingly for an Element

Hope this helps.

C.

AlittleBird2023 commented 1 year ago

Thanks @cleftheris for your quick reponse!

So, in the following example:

    [EdiSegment, EdiSegmentGroup("PO1", SequenceEnd = "CTT")]
    public class OrderDetail
    {
        ...

        [EdiCondition("018", Path = "DTM/0/0")]
        public DTM AvailableFromDate { get; set; }

        [EdiCondition("067", Path = "DTM/0/0")]
        public DTM ArrivalDate  { get; set; }

        [EdiCondition("002", Path = "DTM/0/0")]
        public DTM DeliveryRequestedDate { get; set; }

        [EdiCondition("038", Path = "DTM/0/0")]
        public DTM ShipNoLaterDate { get; set; }

        ...
    }

    [EdiSegment, EdiPath("DTM")]
    public class DTM
    {
        [EdiValue(Path = "DTM/0", Description = "DTM01 - Date/Time Qualifier")]
        public string DateTimeQualifier { get; set; }

        [EdiValue("9(8)", Path = "DTM/1", Format = "yyyyMMdd", Description = "DTM02 - Date format =CCYYMMDD")]
        public DateTime Date { get; set; }
    }

The condition path "DTM/0/0" in class OrderDetail can be rewritten to "DTM/0" because there are no components in element DateTimeQualifier, right?

cleftheris commented 1 year ago

There are always components involved on the value level. For example the following line represents a DTM segment with one element and inside of that one component DTM+137 While this has one element and 3 components. DTM+137:20060619165058:203

The component it there regardless of the delimiter. For the condition attribute always express the full path for the value - don't use the short versions.

A side note do prefer the explicit EdiSegmentGroup declaration over the SequenceEnd. The former is the one that you have to declare all direct desendant segment names while the latter will only get you so far on simple usecases. Checkout examples in the tests project