I have an object Song that i like to sort based on a parameter given to me from the frontend.
public class Song
{
public int Id { get; set; }
public string Name { get; set; }
public int Year { get; set; }
public string Artist { get; set; }
public int? Bpm { get; set; }
public int Duration { get; set; }
public string Genre { get; set; }
public string Album { get; set; }
}
Is it possible to sort the SongList based on the sort parameter? The parameter can be for example Album, title or artist but basically it could be any of the properties in the Song object.
private List<Song> FilterSongs (List<Song> songs, string genre, string sortBy)
{
List<Song> filteredList = songs.Where(song => song.Genre.Contains(genre)).OrderBy(song => song.sortBy).ToList();
return filteredList;
}
I could just make a case switch with multiple filter options but I was hoping someone would know a nice and clean query.