-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Design.AttributeArgumentsShouldHaveAccessorsRule(2.10)
Sebastien Pouliot edited this page Jan 22, 2011
·
2 revisions
Assembly: Gendarme.Rules.Design
Version: 2.10
This rule fires if a parameter to an Attribute constructor is not exposed using a properly cased property. This is a problem because it is generally not useful to set state within an attribute without providing a way to get at that state.
Bad example:
[AttributeUsage (AttributeTargets.All)]
public sealed class AttributeWithRequiredProperties : Attribute {
private int storedFoo;
private string storedBar;
// we have no corresponding property with the name 'Bar' so the rule will fail
public AttributeWithRequiredProperties (int foo, string bar)
{
storedFoo = foo;
storedBar = bar;
}
public int Foo {
get {
return storedFoo;
}
}
}
Good example:
[AttributeUsage (AttributeTargets.All)]
public sealed class AttributeWithRequiredProperties : Attribute {
private int storedFoo;
private string storedBar;
public AttributeWithRequiredProperties (int foo, string bar)
{
storedFoo = foo;
storedBar = bar;
}
public int Foo {
get {
return storedFoo;
}
}
public string Bar {
get {
return storedBar;
}
}
}
Note that this page was autogenerated (3/17/2011 9:31:58 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!