Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
2010-06-22 Sebastien Pouliot <sebastien@ximian.com>
Browse files Browse the repository at this point in the history
	* PreferEmptyInstanceOverNullRule.cs: Apply AvoidLargeClassesRule


svn path=/trunk/mono-tools/; revision=159400
  • Loading branch information
Sebastien Pouliot committed Jun 22, 2010
1 parent e6efa3d commit 23be02f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
4 changes: 4 additions & 0 deletions gendarme/rules/Gendarme.Rules.BadPractice/ChangeLog
@@ -1,3 +1,7 @@
2010-06-22 Sebastien Pouliot <sebastien@ximian.com>

* PreferEmptyInstanceOverNullRule.cs: Apply AvoidLargeClassesRule

2010-06-13 Sebastien Pouliot <sebastien@ximian.com>

* DisableDebuggingCodeRule.cs:
Expand Down
Expand Up @@ -129,10 +129,10 @@ namespace Gendarme.Rules.BadPractice {
[Solution ("Return an empty instance instead of null.")]
public class PreferEmptyInstanceOverNullRule : ReturnNullRule, IMethodRule {

TypeReference returnType;
bool return_string;
bool return_array;
bool return_ienumerable;
TypeReference return_type;
bool string_return_type;
bool array_return_type;
bool ienumerable_return_type;

public override RuleResult CheckMethod (MethodDefinition method)
{
Expand All @@ -145,12 +145,12 @@ public override RuleResult CheckMethod (MethodDefinition method)
return RuleResult.DoesNotApply;

//only apply to methods returning string, array, or IEnumerable-impl
returnType = method.ReturnType.ReturnType;
return_string = (returnType.FullName == "System.String");
return_array = returnType.IsArray ();
return_ienumerable = returnType.Implements ("System.Collections.IEnumerable");
return_type = method.ReturnType.ReturnType;
string_return_type = (return_type.FullName == "System.String");
array_return_type = return_type.IsArray ();
ienumerable_return_type = return_type.Implements ("System.Collections.IEnumerable");

if (!return_string && !return_array && !return_ienumerable)
if (!string_return_type && !array_return_type && !ienumerable_return_type)
return RuleResult.DoesNotApply;

return base.CheckMethod (method);
Expand All @@ -164,11 +164,11 @@ protected override void Report (MethodDefinition method, Instruction ins)

string SuggestReturnType ()
{
if (return_string)
if (string_return_type)
return "string.Empty";
else if (return_array)
return string.Format ("an empty {0} array", returnType.Name);
else if (return_ienumerable)
else if (array_return_type)
return string.Format ("an empty {0} array", return_type.Name);
else if (ienumerable_return_type)
return "yield break (or equivalent)";
return "an empty collection";
}
Expand Down

0 comments on commit 23be02f

Please sign in to comment.