Last active
March 17, 2019 02:24
-
-
Save glinesbdev/2c75cf3642afc241c5994ebc0634a8dc to your computer and use it in GitHub Desktop.
C# Generic Where
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Classes included for clarity | |
public class MovieList | |
{ | |
IEnumerable<IMovie> Movies { get; set; } | |
} | |
public class Api<T> where T : IMovie | |
{ | |
public IEnumerable<T> GetMovies() | |
{ | |
// Boring implementation details | |
} | |
} | |
public class AppSetup() | |
{ | |
// This is where the problem is | |
private void BuildMovies<T>() where T : IMovie | |
{ | |
// Getting an error here where cannot convert IEnumerable<T> to IEnumerable<IMovie> | |
// I would think the "where" would take care of that. Any thoughts? | |
MovieList list = new MovieList { Movies = Api.GetMovies<T>() }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment