Question

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);
}
Was it helpful?

Solution

You will have to add the attribute for each method.

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top