Skip to content

MultiRecordEngine does not expose Options for all record types #429

@bcallaghan-et

Description

@bcallaghan-et

The MultiRecordEngine class exposes an Options property that lets developers dynamically access and change field properties, but that Options object only contains information about the first record type passed to the MultiRecordEngine's constructor. It is not possible to access the field options of the remaining types.

I have a record type that contains a variable length array. Unfortunately, this array is not the final field in the record. This record type also comes from a third-party, so I have no power to change it. A simplified version of this type is shown below.

[DelimitedRecord("~")]
internal class DetailReject {
    public string RecordType { get; set; }
    public int NumberOfErrorCodes { get; set; }
    public string[] ErrorCodes { get; set; }
    public string ReferenceNumber { get; set; }
}

If I try to use the [FieldArrayLength] attribute on the ErrorCodes property, it demands a single fixed value. The actual count of ErrorCodes is variable and included in the record itself as NumberOfErrorCodes.

I would like to dynamically change the ErrorCodes field options, similar to the Dynamic Engine Options example in the docs. However, I cannot access the options for this field because I'm using the MultiRecordEngine and the record type is not the first type passed to that constructor.

My workaround has been to add a dummy value to the [FieldArrayLength] attribute, and then to use reflection to access the internal and private fields that contain the field options for ErrorCodes. This logic is added to the BeforeRead method of the record type, which sets both ArrayMinLength and ArrayMaxLength to the actual count. FileHelpers then parses the record without issue.

Alternatively, a new API that allowed variable length arrays, with the expected length within the same record type, would be appreciated. Even in my workaround, I can't use the NumberOfErrorCodes property; I have to manually compute the number of error codes using only the RecordLine string. If possible, an attribute such as the following would meet my needs.

    public int NumberOfErrorCodes { get; set; }
    [FieldArrayLength(nameof(NumberOfErrorCodes))]
    public string[] ErrorCodes { get; set; }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions