0

This may be very simple, but it's late in the night... I have two methods:

public IQueryable<Post> GetNotSticky()
{
   return Get().Where(p => p.Type != PostType.Sticky);
}

And the inverse

public IQueryable<Post> GetSticky()
{
   return Get().Where(p => p.Type == PostType.Sticky);
}

As you can see, the operator is the only difference. How to factorize this DRY violation into a nice common method? It feels simple, but right now the solution eludes me.

4

1 回答 1

4
public IQueryable<Post> GetWithSticky(bool isSticky)
{
   return Get().Where(p => (p.Type == PostType.Sticky) == isSticky);
}
于 2012-04-25T23:40:38.080 回答