Class EntitySort
- Namespace
- Arbiter.CommandQuery.Queries
- Assembly
- Arbiter.CommandQuery.dll
Represents a sort expression for an entity, specifying the property to sort by and the sort direction.
public class EntitySort
- Inheritance
-
EntitySort
- Inherited Members
Examples
The following example demonstrates how to use the EntitySort class:
var sort = new EntitySort
{
Name = "Name",
Direction = "asc"
};
Console.WriteLine(sort.ToString()); // Output: "Name:asc"
Remarks
This class is typically used in queries to define sorting criteria for entities. The sort direction can be ascending ("asc") or descending ("desc").
Properties
Direction
Gets or sets the direction of the sort (e.g., "asc" for ascending or "desc" for descending).
[JsonPropertyName("direction")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Direction { get; set; }
Property Value
Name
Gets or sets the name of the property to sort by.
[JsonPropertyName("name")]
public string Name { get; set; }
Property Value
- string
The name of the property to sort by.
Methods
GetHashCode()
Computes the hash code for the current EntitySort instance.
public override int GetHashCode()
Returns
- int
A hash code for the current EntitySort instance.
Parse(string?)
Parses a string representation of a sort expression into an EntitySort instance.
public static EntitySort? Parse(string? sortString)
Parameters
sortString
stringThe sort expression in the format "PropertyName:Direction".
Returns
- EntitySort
An instance of EntitySort for the parsed sort expression, or null if the input is invalid.
Examples
The following example demonstrates how to parse a sort string:
var sort = EntitySort.Parse("Name:desc");
Console.WriteLine(sort?.Name); // Output: "Name"
Console.WriteLine(sort?.Direction); // Output: "desc"
ToString()
Returns a string representation of the current EntitySort instance.
public override string ToString()
Returns
- string
A string representation of the sort expression in the format "PropertyName:Direction". If the direction is not specified, only the property name is returned.