AvoidLackOfCohesionOfMethodsRule evaluating on Visual Basic Code

120 views
Skip to first unread message

Andrew Hanson

unread,
Jan 6, 2012, 11:31:40 AM1/6/12
to gend...@googlegroups.com
I wrote a simple class to demo my problem. Perhaps I'm just misunderstanding something and I have to just deal with it. The class has three properties in it (my example had one string, one integer, and one boolean) with backing fields. I compiled this in VS2008.

I compile this class (and this class only) into a DLL and run the Gendarme UI with the default values, and I get hit with a warning on the AvoidLackOfCohesionOfMethodsRule. I assumed that the MINIMUMMETHODCOUNT would prevent this class from being caught under that rule. I can't find where this property is configured, but I'm assuming the default is higher than zero, which would be my assumption as to the method count for this object.

I've run Gendarme on other, bigger libraries and this is a consistent problem for my POCO types and I've also seen it complain about otehr rulles on  methods I don't have in the class called "set_{PROPNAME}" (with the name of a property). I'm assuming somewhere deep down below these properties are turned into Get and Set methods and that's what's causing me to fail this rule?

Andrew Hanson

unread,
Jan 6, 2012, 1:57:56 PM1/6/12
to gend...@googlegroups.com
I thought my issue was specific to Visual Basic, but it isn't I did the exact same thing in C# and I'm getting the same result. 

I've always found using POCO types useful, but maybe I'm wrong. Should I avoid creating these objects?

mark

unread,
Jan 7, 2012, 9:36:39 AM1/7/12
to gend...@googlegroups.com
I can't seem to find a reference to back me up, but it sounds like the problem is that the methods generated by accessors (get and set) may be counted by Gendarme. Rule doco is here (seems a little out dated):http://www.mono-project.com/Gendarme.Rules.Maintainability#AvoidLackOfCohesionOfMethodsRule

I'm not sure what's happening, as my belief is that the compiler creates get_{prop name} and set_{prop name} methods, and the private fields to match. Someone with more knowledge about Gendarme can aid in this. We could also look at the source code:

https://github.com/mono/mono-tools/blob/master/gendarme/rules/Gendarme.Rules.Maintainability/AvoidLackOfCohesionOfMethodsRule.cs

HTH
Reply all
Reply to author
Forward
0 new messages