Skip to content

Instantly share code, notes, and snippets.

@jskeet
Created February 15, 2017 15:47
Show Gist options
  • Save jskeet/1c63090d847a97cc757352807cfc0a50 to your computer and use it in GitHub Desktop.
Save jskeet/1c63090d847a97cc757352807cfc0a50 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
class Entry {}
class WordEntry : Entry {}
class CharacterEntry : Entry {}
class Program
{
public List<WordEntry> WordDataBase = new List<WordEntry>();
public List<CharacterEntry> CharacterDataBase = new List<CharacterEntry>();
public List<Entry> SelectWhere<T>(System.Func<T, bool> predicate) where T : Entry
{
if (typeof(T) == typeof(WordEntry))
return WordDataBase
.Where((Func<WordEntry, bool>) predicate)
.ToList<Entry>();
else if (typeof(T) == typeof(CharacterEntry))
return CharacterDataBase
.Where((Func<CharacterEntry, bool>) predicate)
.ToList<Entry>();
else
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment