Here is some code that I can't seem to understand how it works. I know it is using generics but what does the "new" in the where clause mean?
public class MediaPresenter<T>
where T : Media, new()
{
public MediaPresenter(string mediaPath, params string[] extensions)
{
_mediaPath = mediaPath;
_fileExtensions = extensions;
}
private void LoadMedia()
{
if(string.IsNullOrEmpty(_mediaPath)) return;
_media = new ObservableCollection<Media>();
DirectoryInfo directoryInfo = new DirectoryInfo(_mediaPath);
foreach(string extension in _fileExtensions)
{
FileInfo[] pictureFiles = directoryInfo.GetFiles(
extension,
SearchOption.AllDirectories
);
foreach(FileInfo fileInfo in pictureFiles)
{
if(_media.Count == 50) break;
T media = new T();
media.SetFile(fileInfo);
_media.Add(media);
}
}
}
}
I also don't understand in the LoadMedia method how the T is used? Can the T get referenced anywhere in the class?