I know the title could probably be a bit more descriptive/better phrased, but it was the best I could come up with.
Currently I have a class with a lot of methods looking like the ones below:
private static void UpdateArtists()
{
artists.Clear();
foreach (AudioInfo entry in library_entries)
{
artists.Add(entry.Artist, entry);
}
}
private static void UpdateAlbums()
{
albums.Clear();
foreach (AudioInfo entry in library_entries)
{
albums.Add(entry.Album, entry);
}
}
private static void UpdateGenres()
{
genres.Clear();
foreach (AudioInfo entry in library_entries)
{
genres.Add(entry.Genre, entry);
}
}
private static void UpdateYears()
{
years.Clear();
foreach (AudioInfo entry in library_entries)
{
years.Add(entry.Year, entry);
}
}
Needless to say, writing dozens of these is very tiresome. So I was wondering if it's possible to simplify it and make a method something like this:
private static void Update(Dictionary<string, AudioInfo> dictionary, AudioInfo.Property property)
{
dictionary.Clear();
foreach (AudioInfo entry in library_entries)
{
dictionary.Add(entry.property, entry);
}
//Where "property" is a property in the AudioInfo-class.
}
Is that doable, and if it is; how?
Thanks!