Search code examples
c#validationcobolediedi.net

How to validate Picture clause in C#?


I am using EDI.Net nuget package. In their Readme.md file, they are talking about "The Picture clause":

The Picture Clause is taken from COBOL laguage and the way it handles expressing numeric and alphanumric data types.

My model looks like this:

[EdiMessage]
public class DeliveryNote
{
    [EdiValue("X(9)", Path = "RFF/0/1")]
    public string Identification { get; set; }
}

I was hoping to use this EdiValue-DataAttribute (source code) to validate my models. It looks like they are already parsing those Picture clauses internally in some way.

I could not figure out how to validate my models, yet. The first obvious idea was to use the .NET Validation classes (Validator, ValidationContext, ...):

var deliveryNote = new DeliveryNote();
deliveryNote.Identification = null;

var context = new ValidationContext(deliveryNote, serviceProvider: null, items: null);
var validationResults = new List<ValidationResult>();
bool isValid = Validator.TryValidateObject(deliveryNote, context, validationResults, true);

It does not seem, that anything is validated.

Where is my mistake? Can you validate those Picture clauses? If this Picture clause support is not for validation, what is their purpose?


Solution

  • Where is my mistake? Can you validate those Picture clauses? If this Picture clause support is not for validation, what is their purpose?

    The picture clause describes the format of a data element. You do not validate the picture clause, but you may validate the contents of the data element--its value. You use the picture clause and other information from user documents to determine validation criteria.

    A previous post touched on what is a picture question. That post also provided a link to one example of segments with their data element descriptions.