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);
}

Simian

I started using Simian to find duplicated code - very nice!

I created a simple cmd file to output the analysis to a text file.

[PathToSimian]\simian-2.3.32.exe
-includes=**/*.cs
-excludes=**\obj\**\*.cs
-excludes=**\Reference.cs
-excludes=**\*.feature.cs
-excludes=**\*.Designer.cs > simian.txt