Skip to content

Instantly share code, notes, and snippets.

@glinesbdev
Last active March 17, 2019 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glinesbdev/2c75cf3642afc241c5994ebc0634a8dc to your computer and use it in GitHub Desktop.
Save glinesbdev/2c75cf3642afc241c5994ebc0634a8dc to your computer and use it in GitHub Desktop.
C# Generic Where
// 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