namespace testcase { public class Program { static void Main(string[] args) { var vote1 = new Vote() { ItemID = 1 }; List votes = new List(); votes.Add(vote1); List strings = new List(); strings.Add("test"); List posts = Post.SortedCollection(strings, ListSortType.Hot, votes); } } public interface IVotable { double HotScore { get; set; } double VoteTotal { get; set; } DateTime CreatedDate { get; set; } } public class SCO : IVotable { public double HotScore { get; set; } public double VoteTotal { get; set; } public DateTime CreatedDate { get; set; } public SCO(string item, List votes) { VoteTotal = 10; HotScore = 10; CreatedDate = DateTime.Now; } public static List SortedCollection(List items, ListSortType sortType, List votes) where T : IVotable { var returnlist = new List(); Type genericType = typeof(T); var functionCreator = FastActivator.GenerateFunc, T>>(); for (int i = 0; i < items.Count; i++) { returnlist.Add(functionCreator(items[i], votes)); } switch (sortType) { case ListSortType.Hot: returnlist.Sort((p1, p2) => p2.HotScore.CompareTo(p1.HotScore)); break; case ListSortType.Top: returnlist.Sort((p1, p2) => p2.VoteTotal.CompareTo(p1.VoteTotal)); break; case ListSortType.Recent: returnlist.Sort((p1, p2) => p2.CreatedDate.CompareTo(p1.CreatedDate)); break; } return returnlist; } } public class Vote { public double ItemID { get; set; } } public class VoteMeta { public double UpVotes { get; set; } public double DownVotes { get; set; } public string CurrentUserVoteClass { get; set; } } public enum ListSortType { Hot, Top, Recent }; public class Post : SCO { public string Summary { get; set; } public Uri Link { get; set; } public Post(string item, List votes) : base(item, votes) { Summary = "Summary"; Link = new UriBuilder("http://www.google.com").Uri; } } }