Recently, I've encountered a scenario in my C# project where I need to handle a SQL sort order parameter within a function:
public static string BuildSortClause(string colId, string sortOrder) {
...
}
Specifically, I want to ensure that only 'ASC' or 'DESC' are accepted as valid sortOrder strings during compilation. Any other input should result in a failure. If this were Typescript, I could easily achieve this by using a Template Literal Type for the parameter like so:
type SortOrder = 'ASC' | 'DESC';
My question is: What is the most similar solution in C# to restrict the type of strings allowed for this parameter?