I have a function for merging data from an object (a PrintTestDataItem
) into a template file for a printed label (a LabelFormatDocument
called label in this snippet). The LabelFormatDocument
is a third-party class that I use to set various fields on my label and I do this by setting the numerous substrings to the values that I want from my PrintTestDataItem
object.
There are a lot of these substrings and my current function just sets each substring sequentially, which is obviously not an ideal way to do this sort of operation. What would be a better way to set these substrings programmatically and any other suggestions for increasing the maintainability of this function?
My first idea is to use a dictionary to store the substring names and map them to the appropriate parameter of the PrintTestDataItem
, is this the right path to go down?
public void MergePrintData(PrintTestDataItem printTestData)
{
label.SubStrings["Barcode"].Value = printTestData.IDNumber.ToString();
label.SubStrings["Date"].Value = printTestData.TestDate.ToString();
label.SubStrings["WRN"].Value = printTestData.WRNNumber;
label.SubStrings["Operator"].Value = printTestData.OperatorName;
label.SubStrings["PrintheadType"].Value = printTestData.HeadType;
label.SubStrings["PrintheadSerial"].Value = printTestData.HeadSerial;
label.SubStrings["Batch"].Value = printTestData.BatchNumber;
label.SubStrings["PrintFrequency"].Value = (printTestData.PrintFrequency + "kHz");
label.SubStrings["PrintDistance"].Value = (printTestData.PrintDistance + "mm");
label.SubStrings["InkType"].Value = printTestData.InkType.ToString();
label.SubStrings["InkColour"].Value = printTestData.InkColour;
label.SubStrings["InkTemperature"].Value = (printTestData.InkTemperature + "°C");
label.SubStrings["DifferentialPressure"].Value = (printTestData.DifferentialPressure + "mBar");
label.SubStrings["MeniscusPressure"].Value = (printTestData.MeniscusPressure + "mBar");
label.SubStrings["Comments"].Value = printTestData.Comments;
label.SubStrings["EncoderDivide"].Value = printTestData.EncoderDivide;
label.SubStrings["EncoderMultiply"].Value = printTestData.EncoderMultiply;
label.SubStrings["Offset"].Value = printTestData.Offset;
label.SubStrings["NumberOfGreyLevels"].Value = printTestData.NumberOfGreyLevels;
label.SubStrings["Mirror"].Value = BooleanRemapping(printTestData.Mirror);
label.SubStrings["DIR"].Value = BooleanRemapping(printTestData.DIR);
label.SubStrings["ReversePrint"].Value = BooleanRemapping(printTestData.ReversePrint);
label.SubStrings["PrintDirection"].Value = printTestData.PrintDirection.ToString();
label.SubStrings["PrintMode"].Value = printTestData.PrintMode.ToString();
label.SubStrings["PrintTransportMode"].Value = printTestData.PrintTransportMode.ToString();
label.SubStrings["AmbientTemperature"].Value = (printTestData.AmbientTemperature + "°C");
label.SubStrings["HoursRun"].Value = printTestData.HoursRun;
label.SubStrings["LinesDown"].Value = printTestData.LinesDown;
}