Author: spouliot
Date: 2008-01-03 07:42:31 -0500 (Thu, 03 Jan 2008)
New Revision: 92167
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/AvoidReturningArraysOnPropertiesRule.cs
Modified:
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/ChangeLog
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Gendarme.Rules.Performance.mdp
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Gendarme.Rules.Performance.xml.in
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Makefile.am
Log:
2008-01-03 Sebastien Pouliot <[EMAIL PROTECTED]>
* AvoidReturningArraysOnPropertiesRule.cs: New. Rule to warn for
properties that returns arrays. By Adrian Tsai.
* Gendarme.Rules.Performance.xml.in: Add rule description.
* Gendarme.Rules.Performance.mdp: Add rule to MonoDevelop project
file.
* Makefile.am: Add rule and tests to the build.
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/AvoidReturningArraysOnPropertiesRule.cs
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/AvoidReturningArraysOnPropertiesRule.cs
2008-01-03 12:40:20 UTC (rev 92166)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/AvoidReturningArraysOnPropertiesRule.cs
2008-01-03 12:42:31 UTC (rev 92167)
@@ -0,0 +1,51 @@
+//
+// Gendarme.Rules.Performance.AvoidReturningArraysOnPropertiesRule
+//
+// Authors:
+// Adrian Tsai <[EMAIL PROTECTED]>
+//
+// Copyright (c) 2007 Adrian Tsai
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+
+using Mono.Cecil;
+
+using Gendarme.Framework;
+using Gendarme.Framework.Rocks;
+
+namespace Gendarme.Rules.Performance {
+
+ public class AvoidReturningArraysOnPropertiesRule : IMethodRule {
+
+ public MessageCollection CheckMethod (MethodDefinition method,
Runner runner)
+ {
+ if (!method.IsGetter ())
+ return runner.RuleSuccess;
+
+ if (!method.ReturnType.ReturnType.IsArray ())
+ return runner.RuleSuccess;
+
+ Location loc = new Location (method);
+ Message msg = new Message ("Avoid returning arrays from
properties.", loc, MessageType.Warning);
+ return new MessageCollection (msg);
+ }
+ }
+}
Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/ChangeLog
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/ChangeLog
2008-01-03 12:40:20 UTC (rev 92166)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/ChangeLog
2008-01-03 12:42:31 UTC (rev 92167)
@@ -1,3 +1,12 @@
+2008-01-03 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * AvoidReturningArraysOnPropertiesRule.cs: New. Rule to warn for
+ properties that returns arrays. By Adrian Tsai.
+ * Gendarme.Rules.Performance.xml.in: Add rule description.
+ * Gendarme.Rules.Performance.mdp: Add rule to MonoDevelop project
+ file.
+ * Makefile.am: Add rule and tests to the build.
+
2007-12-21 Nestor Salceda <[EMAIL PROTECTED]>
* AvoidUnusedParameterRule.cs: If the method is anonymous then, gendarme
Modified:
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Gendarme.Rules.Performance.mdp
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Gendarme.Rules.Performance.mdp
2008-01-03 12:40:20 UTC (rev 92166)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Gendarme.Rules.Performance.mdp
2008-01-03 12:42:31 UTC (rev 92167)
@@ -7,23 +7,23 @@
<CodeGeneration compiler="Csc" warninglevel="4" optimize="True"
unsafecodeallowed="False" generateoverflowchecks="True"
generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
</Configuration>
<Configuration name="Release" ctype="DotNetProjectConfiguration">
- <Output directory="./bin/Release" assembly="Gendarme.Rules.Performance"
/>
+ <Output directory="bin/Release" assembly="Gendarme.Rules.Performance" />
<Build debugmode="False" target="Library" />
<Execution runwithwarnings="True" consolepause="False" runtime="MsNet"
clr-version="Net_2_0" />
<CodeGeneration compiler="Csc" warninglevel="4" optimize="True"
unsafecodeallowed="False" generateoverflowchecks="True"
generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
</Configuration>
</Configurations>
<Contents>
- <File name="./EmptyDestructorRule.cs" subtype="Code" buildaction="Compile"
/>
- <File name="./IDisposableWithDestructorWithoutSuppressFinalizeRule.cs"
subtype="Code" buildaction="Compile" />
- <File name="./UseStringEmptyRule.cs" subtype="Code" buildaction="Compile"
/>
- <File name="./Gendarme.Rules.Performance.xml.in" subtype="Code"
buildaction="Nothing" />
- <File name="./AvoidUnusedParametersRule.cs" subtype="Code"
buildaction="Compile" />
- <File name="./AvoidUncalledPrivateCodeRule.cs" subtype="Code"
buildaction="Compile" />
- <File name="./AvoidUninstantiatedInternalClassesRule.cs" subtype="Code"
buildaction="Compile" />
- <File name="./UsingStringLengthInsteadOfCheckingEmptyStringRule.cs"
subtype="Code" buildaction="Compile" />
- <File name="./AvoidToStringOnStringsRule.cs" subtype="Code"
buildaction="Compile" />
- <File name="./DontIgnoreMethodResultRule.cs" subtype="Code"
buildaction="Compile" />
+ <File name="EmptyDestructorRule.cs" subtype="Code" buildaction="Compile" />
+ <File name="IDisposableWithDestructorWithoutSuppressFinalizeRule.cs"
subtype="Code" buildaction="Compile" />
+ <File name="UseStringEmptyRule.cs" subtype="Code" buildaction="Compile" />
+ <File name="Gendarme.Rules.Performance.xml.in" subtype="Code"
buildaction="Nothing" />
+ <File name="AvoidUnusedParametersRule.cs" subtype="Code"
buildaction="Compile" />
+ <File name="AvoidUncalledPrivateCodeRule.cs" subtype="Code"
buildaction="Compile" />
+ <File name="AvoidUninstantiatedInternalClassesRule.cs" subtype="Code"
buildaction="Compile" />
+ <File name="UsingStringLengthInsteadOfCheckingEmptyStringRule.cs"
subtype="Code" buildaction="Compile" />
+ <File name="AvoidToStringOnStringsRule.cs" subtype="Code"
buildaction="Compile" />
+ <File name="DontIgnoreMethodResultRule.cs" subtype="Code"
buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Project" localcopy="True" refto="framework" />
Modified:
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Gendarme.Rules.Performance.xml.in
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Gendarme.Rules.Performance.xml.in
2008-01-03 12:40:20 UTC (rev 92166)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Gendarme.Rules.Performance.xml.in
2008-01-03 12:42:31 UTC (rev 92167)
@@ -1,4 +1,10 @@
<rules>
+ <rule Name="AvoidReturningArraysOnPropertiesRule"
+
Type="Gendarme.Rules.Performance.AvoidReturningArraysOnPropertiesRule,
Gendarme.Rules.Performance, [EMAIL PROTECTED]@, Culture=neutral,
PublicKeyToken=null"
+
Uri="http://www.mono-project.com/Gendarme#AvoidReturningArraysOnPropertiesRule"
>
+ <problem>The property '{0}' returns an array.</problem>
+ <solution>Change the property to a method.</solution>
+ </rule>
<rule Name="EmptyDestructorRule"
Type="Gendarme.Rules.Performance.EmptyDestructorRule,
Gendarme.Rules.Performance, [EMAIL PROTECTED]@, Culture=neutral,
PublicKeyToken=null"
Uri="http://www.mono-project.com/Gendarme#EmptyDestructorRule" >
Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Makefile.am
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Makefile.am
2008-01-03 12:40:20 UTC (rev 92166)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/Makefile.am
2008-01-03 12:42:31 UTC (rev 92167)
@@ -12,13 +12,13 @@
performance_rules_sources = EmptyDestructorRule.cs
IDisposableWithDestructorWithoutSuppressFinalizeRule.cs \
UseStringEmptyRule.cs AvoidUnusedParametersRule.cs
AvoidUninstantiatedInternalClassesRule.cs \
AvoidUncalledPrivateCodeRule.cs AvoidToStringOnStringsRule.cs
DontIgnoreMethodResultRule.cs \
- UsingStringLengthInsteadOfCheckingEmptyStringRule.cs
+ UsingStringLengthInsteadOfCheckingEmptyStringRule.cs
AvoidReturningArraysOnPropertiesRule.cs
performance_rules_build_sources = $(addprefix $(srcdir)/,
$(performance_rules_sources))
performance_rules_build_sources += $(performance_rules_generated_sources)
../../bin/Gendarme.Rules.Performance.dll: $(performance_rules_build_sources)
- $(MCS) -debug -target:library -pkg:mono-cecil
-r:../../bin/Gendarme.Framework.dll -out:$@ $(performance_rules_build_sources)
+ $(MCS) -debug -target:library -langversion:linq -pkg:mono-cecil
-r:../../bin/Gendarme.Framework.dll -out:$@ $(performance_rules_build_sources)
cp Gendarme.Rules.*.xml ../../bin/
# Install Unstable Mono Libraries (see configure.ac)
@@ -38,7 +38,7 @@
performance_test_sources = EmptyDestructorTest.cs
IDisposableWithDestructorWithoutSuppressFinalizeTest.cs \
UseStringEmptyTest.cs AvoidUnusedParametersTest.cs
UsingStringLengthInsteadOfCheckingEmptyStringTest.cs \
AvoidUncalledPrivateCodeTest.cs AvoidToStringOnStringsTest.cs
AvoidUninstantiatedInternalClassesTest.cs \
- DontIgnoreMethodResultTest.cs
+ DontIgnoreMethodResultTest.cs AvoidReturningArraysOnPropertiesTest.cs
performance_test_build_sources = $(addprefix $(srcdir)/Test/,
$(performance_test_sources))
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches