Detailed Method Reference
Namespace: Canley.Utility.CSV.Standard
Class: CSVTable<T>
Definition
public void SortByField(string fieldName, bool ascending = true)-
Description: Sorts the loaded records collection dynamically by a specified field name using reflection and comparable interfaces.
-
Workflow:
- Size Guard: Verifies that the table contains at least two records to warrant sorting operations.
- Field Resolution: Uses reflection to find the public instance field matching the string name, supporting case-insensitive lookups.
- Comparison Sort: Evaluates record values, safely handles null references, and sorts the internal list either ascending or descending based on
IComparableimplementations.
-
Parameters:
fieldName: The string name of the public field to sort the records by.ascending: Determines the sort direction; defaults totruefor ascending order.
-
Returns:
void -
Example:
public void SortInventoryByValue(CSVTable<ItemRecord> itemTable)
{
itemTable.SortByField("goldValue", ascending: false);
Debug.Log(message: "Inventory table sorted by gold value in descending order.");
}TIP
Use
SortByFieldwhen implementing sortable columns in runtime UI grids or when organizing records for sequential processing.