Attributes are powerful, useful, but very limited in several aspects. But — rejoice! — not that limited as you might think. They still allow some good set of parameter types:
http://msdn.microsoft.com/en-us/library/ms177221%28v=vs.100%29.aspx[
^].
This is how it may look in your case:
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
class PexMethodAttribute : System.Attribute {
public int MaxBranches { internal get; set; }
}
Pay attention for
internal
. You can check the attribute valued only in the same assembly where it is declared, which is pretty reasonable. Most likely, you will need to have the setter
set
public, because you set it in the code applying the attribute.
Here is how you can apply your attribute type to some method:
[PexMethod(MaxBranches = 1000)]
void SomeMethod() {}
Alternatively, you can use constructor syntax for the parameter:
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
class PexMethodAttribute : System.Attribute {
internal int MaxBranches { get; set; }
public PexMethodAttribute(int maxBranches) { this.MaxBranches = maxBranches; }
}
And the application of it would look a bit different:
[PexMethod(1010)]
void SomeMethod() {}
—SA