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:

    1. Size Guard: Verifies that the table contains at least two records to warrant sorting operations.
    2. Field Resolution: Uses reflection to find the public instance field matching the string name, supporting case-insensitive lookups.
    3. Comparison Sort: Evaluates record values, safely handles null references, and sorts the internal list either ascending or descending based on IComparable implementations.
  • Parameters:

    • fieldName: The string name of the public field to sort the records by.
    • ascending: Determines the sort direction; defaults to true for 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 SortByField when implementing sortable columns in runtime UI grids or when organizing records for sequential processing.