menu_bookDocumentation
s&box PackageSortMode: Package sorting modes
PackageSortMode Enum
PackageSortMode is a typed enum for package sorting modes in the s&box package browser. It provides a type-safe way to specify how packages should be sorted when querying the package API. The enum includes an extension method ToIdentifier() that converts the enum value to the string format expected by the package API.
Enum Values
CSHARP
public enum PackageSortMode
{
Popular,
Newest,
Trending,
Random
}Extension Method
CSHARP
public static class PackageSortModeExtensions
{
public static string ToIdentifier(this PackageSortMode sortMode)
{
return sortMode switch
{
PackageSortMode.Popular => "popular",
PackageSortMode.Newest => "newest",
PackageSortMode.Trending => "trending",
PackageSortMode.Random => "random",
_ => "popular"
};
}
}Usage
CSHARP
// Convert to API identifier
var mode = PackageSortMode.Trending;
var identifier = mode.ToIdentifier(); // "trending"
// Use in package queries
var packages = await Package.FindAsync(sortMode: PackageSortMode.Newest);Notes
- Used by the package browser for sorting options in the UI
- ToIdentifier() converts to the string format expected by the package API
- Default fallback is "popular" for unknown values
- Popular sorts by download count or rating
- Newest sorts by publication date
- Trending sorts by recent popularity trends
- Random provides a random selection of packages
Was this helpful?