indice-co / indice-co/EDI.Net

[Q] Dealing with optional segment properties and segments

Open
#228 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
490
Forks
173
PR merge metrics
No merged PRs in 30d

Description

I am wondering what is the best way for dealing with optional segments and segment properties, so that I dont end up with a complex object structure that has a large amount of null values?

For example, given an NM1 X12 EDI Segment, which has a total of 12 possible fields, however only the first two or mandatory. Making those optional fields nullable (as shown in the below codeblock) in my model seems to have no effect.

```

[EdiSegment, EdiPath("NM1")]
public class NM1
{
[EdiValue("X(3)", Path = "NM1/0", Description = "NM101 - Entity Identifier Code")]
public string EntityIdentifierCode { get; set; }

[EdiValue("X(1)", Path = "NM1/1", Description = "NM102 - Entity Type Qualifier")]
public string EntityTypeQualifier { get; set; }

[EdiValue("X(60)", Path = "NM1/2", Description = "NM103 - Name Last or Organization Name")]
public string? NameLastOrOrganizationName { get; set; }

[EdiValue("X(35)", Path = "NM1/3", Description = "NM104 - Name First")]
public string? NameFirst { get; set; }
...
```

This issue also presents itself when using the segments to create complex EdiSegmentGroup's.

```
[EdiSegmentGroup("NM1", new[] { "PER", "N3", "N4", "DMG", "EC", "ICM", "AMT", "HLH", "HI", "LUI" })]
public class Loop2100 : NM1
{
public PER PER { get; set; }
public N3? N3 { get; set; }
...
```

The result is many optional properties with many null values. Is there any way to avoid this?

Thanks in advance!

Contributor guide

No contributing guide indexed for this repository

Research direction

No file, test, or entry point is identified; start by reading the NM1 and Loop2100 examples and locating the implementation of the EdiValue, EdiSegment, and EdiSegmentGroup attributes. Done means optional fields and segments can be represented without a large set of null-valued properties, with the behavior verified for these examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.