uniformrowtype

Introduction

UniformRowType can be used to load the CSV data in a more raw format rather than generating a custom class for the CSV. This is useful if the data in the CSV needs to be accessed by row and column index rather than by class member names. For this guide we'll be using a CSV with the following data:

Default Functionality

Before changing the UniformRowType value, we should look at the code generated by Glue for this CSV. The class that contains the CSV will have a dictionary of objects as shown in the following code:

public static System.Collections.Generic.Dictionary<string, RedgrinTest3.DataTypes.Csv> CsvFile { get; set; }

In this case the Csv class is generated as shown in the following snippet:

public partial class Csv
{
    public string Column1;
    public string Column2;
    public string Column3;
    ...

In this case we could access the CSV data through the CsvFile member. If the CSV were part of GlobalContent we could get the information as shown in the following code:

var value = GlobalContent.CsvFile["Value 1"].Column1;

Note that we access the first column using the Column1 property.

Setting UniformRowType

We can change the UniformRowType to string[] to change how Glue generates the CSV code.

This setting tells Glue to generate each row in the CSV as a string[], allowing us to index into each column as shown in the following code:

var value = GlobalContent.CsvFile["Value 1"][0];

String vs. String[]

Glue offers two options for UniformRowType:

  1. String

  2. String[]

The most commonly used value is String[] which tells glue that each row contains multiple values. Since each value in a row may need to be independently accessed, each row is represented as a string array. For example, to access index 3 in a row, your code may look like:

var row = LoadedCsv[2]; // row at index 2
var value = row[3]; // value at index 3 in the selected row

If your CSV has only one column, then the UniformRowType can be String. This can simplify accessing the row. For example, to access the first item in the row at index 2, your code may look like:

var value = LoadedCsv[2]; // this is a string

Last updated