How would you abstract these two functions together most cleanly? - C#