protected static List<Comment> GetTopCommentList(Comment[] allComments) { List<Comment> topComments = new List<Comment>(); foreach (Comment comment in allComments) { // Builds and sorts empty list until sufficiently large if (topComments.Count() < TOP_COMMENTS_TO_GRAB) { topComments.Add(comment); topComments = topComments.OrderByDescending(c => c.Upvotes).ToList(); } else { foreach (Comment topComment in topComments) { if (comment.Upvotes > topComment.Upvotes) { // Compares comment against descending list and then re-sorts once inserted topComments.Remove(topComment); topComments.Add(comment); topComments = topComments.OrderByDescending(c => c.Upvotes).ToList(); break; } } } } return topComments; }
private void GetUserMentions(Comment comment) { foreach (var comm in comment.Comments) { var regx = new Regex("//u/(?:.*) /", RegexOptions.IgnoreCase); var ms = regx.Matches(comm.Body); foreach (Match m in ms) { _userNameMentions.Add(new UserNameMention { UserName = m.ToString(), Subject = "userName mention", Text = "You were mentioned in a [comment](" + comm.Shortlink + ")" }); } GetUserMentions(comment); } }