views:

454

answers:

3

I have interface in service layer with several methods starting with Get and FxCop's Use properties where appropriate rule complains that I should consider using properties instead.

I tried to use SuppressMessageAttribute but when it's defined on interface it has no effect on member methods. Do I need to put SuppressMessageAttribute to every method or is there a way to suppress CA1024 for a whole type?

[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate"]
public interface IProjectService
{
 // Information and statistics about projects
 IList<ProjectInfo> GetProjects();
 ProjectsDashboard GetProjectsDashboard();

 // Project's settings
 ProjectSettings GetProjectSettings(Guid id);

 void SaveProjectSettings(ProjectSettings settings);
}
+3  A: 

You will have to add the attribute for each method.

Sesh
+1  A: 

You will have to apply it to every method, unfortunately.

Also, I'm not seeing any reason here to have your Get methods. Why not just have read only properties, at least for the ProjectsDashboard and the IList<ProjectInfo>. Those don't strike me as implementations that would modify the state of the implementation, and should probably be properties anyways.

The ProjectSettings should also return an indexed collection it would seem as well.

casperOne
Service layer calls methods from data layer so these methods can have different results even when the caller doesn't modify object's state.Calling them can be expensive so I used methods there.
Jozef Izso
+1  A: 

I understand the need to use methods here. While it is true that these methods probably don't change the state, using a method hints at a lengthy/outward operation, which is probably the case through Service Class methods.

Can't you rename your methods to LoadProjectSettings ?

Otherwise you will indeed have to add the attribute to each method, or disable the rule.

Bertvan
The Load prefix is good idea but it can be impossible to rename methods when somebody else already implemented an interface.This is just mine personal project so I can refactor it. But personally I do like the Get version most.
Jozef Izso
Well, if you want to name it against the FxCop rules, you'll just have to bear with the warning. Or disable it generally or disable it each time you use it in place :)
Bertvan
I think this rule is really good but I just don't want in on layer interfaces :) Don't why Scope="member" doesn't work :(
Jozef Izso