Saturday, July 2, 2011

CA1024: Use properties where appropriate

For a long time I had no understanding of the code analysis rule CA1024: "Use properties where appropriate."

I have often violated this rules with methods named Get*, without parameters, that returns a list of items, like

public interface IBlogRepository
{
IEnumerable GetBlogPosts();
}


I have now realized that this is probably an error, since there should always be some kind of paging (see also Ayendes comments on this).

So the correct solution is something like

public interface IBlogRepository
{
IEnumerable GetBlogPosts(int pageSize, int pageNumber);
}

No comments: