diff options
author | Stepan Sindelar <me@stevesindelar.cz> | 2012-03-17 18:56:11 +0400 |
---|---|---|
committer | Stepan Sindelar <me@stevesindelar.cz> | 2012-03-17 18:56:11 +0400 |
commit | 0385f63e25f6ea63e24040bfbefb3cf2b9ef29d5 (patch) | |
tree | a603618ecf41b0ad7d482c6e22f90d5126920d50 /gendarme | |
parent | 8e81fd26112b4fe792822b42da8a3243360ba4d9 (diff) |
Code formatting updated
Diffstat (limited to 'gendarme')
-rw-r--r-- | gendarme/rules/Gendarme.Rules.Performance/AvoidUnusedPrivateFieldsRule.cs | 49 | ||||
-rw-r--r-- | gendarme/rules/Gendarme.Rules.Performance/Test/AvoidUnusedPrivateFieldsTest.cs | 38 |
2 files changed, 44 insertions, 43 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Performance/AvoidUnusedPrivateFieldsRule.cs b/gendarme/rules/Gendarme.Rules.Performance/AvoidUnusedPrivateFieldsRule.cs index 6f612ee9..c7ff3abf 100644 --- a/gendarme/rules/Gendarme.Rules.Performance/AvoidUnusedPrivateFieldsRule.cs +++ b/gendarme/rules/Gendarme.Rules.Performance/AvoidUnusedPrivateFieldsRule.cs @@ -28,6 +28,7 @@ using System; using System.Collections.Generic; + using Mono.Cecil; using Mono.Cecil.Cil; @@ -111,12 +112,12 @@ namespace Gendarme.Rules.Performance { } // scan all methods, including constructors, to find if the field is used - CheckFieldsUsageInType(type); + CheckFieldsUsageInType (type); - // scan nested types becuase they also have access to private types of their parent - foreach (TypeDefinition nested in type.NestedTypes) { - CheckFieldsUsageInType(nested); - } + // scan nested types becuase they also have access to private types of their parent + foreach (TypeDefinition nested in type.NestedTypes) { + CheckFieldsUsageInType (nested); + } // check remaining (private) fields in the set foreach (FieldDefinition field in fields) { @@ -125,25 +126,25 @@ namespace Gendarme.Rules.Performance { return Runner.CurrentRuleResult; } - private void CheckFieldsUsageInType (TypeDefinition type) - { - foreach (MethodDefinition method in type.Methods) { - if (!method.HasBody) - continue; - - // don't check the method if it does not access any field - if (!OpCodeEngine.GetBitmask (method).Intersect (LoadStoreFields)) - continue; - - foreach (Instruction ins in method.Body.Instructions) { - FieldDefinition fd = ins.GetField (); - if (fd == null) - continue; - - fields.Remove (fd); - } - } - } + private void CheckFieldsUsageInType (TypeDefinition type) + { + foreach (MethodDefinition method in type.Methods) { + if (!method.HasBody) + continue; + + // don't check the method if it does not access any field + if (!OpCodeEngine.GetBitmask (method).Intersect (LoadStoreFields)) + continue; + + foreach (Instruction ins in method.Body.Instructions) { + FieldDefinition fd = ins.GetField (); + if (fd == null) + continue; + + fields.Remove (fd); + } + } + } #if false public void Bitmask () diff --git a/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidUnusedPrivateFieldsTest.cs b/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidUnusedPrivateFieldsTest.cs index 47a08ec4..c8c6bd01 100644 --- a/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidUnusedPrivateFieldsTest.cs +++ b/gendarme/rules/Gendarme.Rules.Performance/Test/AvoidUnusedPrivateFieldsTest.cs @@ -163,24 +163,24 @@ namespace Test.Rules.Performance { AssertRuleSuccess<GenericUsed<int>> (); } - class FieldsUsedInNested { - private bool field; - - private static string staticField; - - class Nested { - public void Foo (FieldsUsedInNested parent) - { - FieldsUsedInNested.staticField = "bar"; - parent.field = true; - } - } - } - - [Test] - public void FieldsUsedInNestedType () - { - AssertRuleSuccess<FieldsUsedInNested> (); - } + class FieldsUsedInNested { + private bool field; + + private static string staticField; + + class Nested { + public void Foo (FieldsUsedInNested parent) + { + FieldsUsedInNested.staticField = "bar"; + parent.field = true; + } + } + } + + [Test] + public void FieldsUsedInNestedType () + { + AssertRuleSuccess<FieldsUsedInNested> (); + } } } |