AvoidLackOfCohesionOfMethodsRule evaluating on Visual Basic Code

瀏覽次數:120 次
跳到第一則未讀訊息

Andrew Hanson

未讀,
2012年1月6日 上午11:31:402012/1/6
收件者: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

未讀,
2012年1月6日 下午1:57:562012/1/6
收件者: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

未讀,
2012年1月7日 上午9:36:392012/1/7
收件者: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
回覆所有人
回覆作者
轉寄
0 則新訊息