1

I'm creating a new message, by setting the indexers, like:

Iso8583 isoMsg = new Iso8583();
isoMsg[field] = value; 

I noticed that I'm not receiving any exceptions; following the code I've seen that the validator is not running when I'm setting the fields this way; it only executes when unpacking a byte[] message. Do you think it would be possible to adapt the format and length validators to run also when setting a field?

Thanks in advance!

Federico
  • 576
  • 4
  • 20
  • If you would like fail fast added to the library, please log an issue at https://bitbucket.org/openisoj/openiso8583.net/issues?status=new&status=open – John Oxley May 20 '14 at 08:10

2 Answers2

2

The validators are run on the fields when you call .Pack() on the message.

John Oxley
  • 14,698
  • 18
  • 53
  • 78
1

I guess you just set the value to one of the existing fields form the default template

When you create Iso8583() it uses the DefaultTemplate, which adds the set of default fields into the message instance on creation.

Indexer property is derived from AMessage class, which is Iso8583 class is inherited from.

public string this[int field]
{
    get { return this.GetFieldValue(field); }
    set { this.SetFieldValue(field, value); }
}

These methods:

protected string GetFieldValue(int field)
{
    return this.bitmap[field] ? this.fields[field].Value : null;
}

protected void SetFieldValue(int field, string value)
{
    if (value == null)
    {
        this.ClearField(field);
        return;
    }

    this.GetField(field).Value = value;
}

So it seems that your code sets the value for one of the field from the default template

isoMsg[field] = value; 
Dmitry Pavlov
  • 30,789
  • 8
  • 97
  • 121