diff options
author | Jb Evain <jbevain@gmail.com> | 2012-02-15 17:06:40 +0400 |
---|---|---|
committer | Jb Evain <jbevain@gmail.com> | 2012-02-15 17:06:40 +0400 |
commit | 0827dbf2e81fa0f485f73955885e4bfc7304a389 (patch) | |
tree | 2017d468090f4dd4a5ef9f1408dc3eb30c9afcc2 /gendarme | |
parent | 5a356dd4c56cef94c32e967790f4c305a5194b16 (diff) | |
parent | 9840c380c57ab5c7d9fc3a0efdd584bf79ccab91 (diff) |
Merge pull request #21 from krijesta/attribute-rule
Attributes with inherited properties come up as errors in AttributeArgumentsShouldHaveAccessorsRule
Diffstat (limited to 'gendarme')
-rw-r--r-- | gendarme/rules/Gendarme.Rules.Design/AttributeArgumentsShouldHaveAccessorsRule.cs | 15 | ||||
-rw-r--r-- | gendarme/rules/Gendarme.Rules.Design/Test/AttributeArgumentsShouldHaveAccessorsTest.cs | 35 |
2 files changed, 46 insertions, 4 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Design/AttributeArgumentsShouldHaveAccessorsRule.cs b/gendarme/rules/Gendarme.Rules.Design/AttributeArgumentsShouldHaveAccessorsRule.cs index b46ac4a8..cc037aa3 100644 --- a/gendarme/rules/Gendarme.Rules.Design/AttributeArgumentsShouldHaveAccessorsRule.cs +++ b/gendarme/rules/Gendarme.Rules.Design/AttributeArgumentsShouldHaveAccessorsRule.cs @@ -107,11 +107,18 @@ namespace Gendarme.Rules.Design { // look through getters allProperties.Clear (); - foreach (PropertyDefinition property in type.Properties) { - if (property.GetMethod != null) { - allProperties.Add (property.Name); + + TypeDefinition t = type; + // Walk up the inheritance tree so that inherited properties are counted + do + { + foreach (PropertyDefinition property in t.Properties) { + if (property.GetMethod != null) { + allProperties.Add (property.Name); + } } - } + t = t.BaseType != null ? t.BaseType.Resolve () : null; + } while (t != null && !t.IsNamed ("System", "Attribute")); // look through parameters foreach (MethodDefinition constructor in type.Methods) { diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/AttributeArgumentsShouldHaveAccessorsTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/AttributeArgumentsShouldHaveAccessorsTest.cs index 06408054..02c92a02 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/AttributeArgumentsShouldHaveAccessorsTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/AttributeArgumentsShouldHaveAccessorsTest.cs @@ -196,6 +196,35 @@ namespace Test.Rules.Design { } } + internal abstract class FooAttribute : Attribute + { + protected FooAttribute (string foo) + { + this.Foo = foo; + } + + public string Foo + { + get; + private set; + } + } + + internal class FooBarAttribute : FooAttribute + { + protected FooBarAttribute (string foo, string bar) : base (foo) + { + this.Bar = bar; + } + + public string Bar + { + get; + private set; + } + } + + [TestFixture] public class AttributeArgumentsShouldHaveAccessorsTest : TypeRuleTestFixture<AttributeArgumentsShouldHaveAccessorsRule> { @@ -252,5 +281,11 @@ namespace Test.Rules.Design { { AssertRuleFailure<TwoAccessorsMissingAttribute> (2); } + + [Test] + public void TestInheritedPropertiesAttribute () + { + AssertRuleSuccess<FooBarAttribute> (); + } } } |