Define accessors for attribute arguments
Define accessors for attribute arguments
Microsoft docsDescription
Attributes can define mandatory arguments that must be specified when you apply the attribute to a target. These are also known as positional arguments because they are supplied to attribute constructors as positional parameters. For every mandatory argument, the attribute should also provide a corresponding read-only property so that the value of the argument can be retrieved at execution time. This rule checks that for each constructor parameter, you have defined the corresponding property.
Attributes can also define optional arguments, which are also known as named arguments. These arguments are supplied to attribute constructors by name and should have a corresponding read/write property.
For mandatory and optional arguments, the corresponding properties and constructor parameters should use the same name but different casing. Properties use Pascal casing, and parameters use camel casing.
Cause
In its constructor, an attribute defines arguments that do not have corresponding properties.
How to fix violations
To fix a violation of this rule, add a read-only property for each constructor parameter that does not have one.
Example
#pragma warning disable CA1019
// The code that's violating the rule is on this line.
#pragma warning restore CA1019When to suppress
Suppress a warning from this rule if you do not want the value of the mandatory argument to be retrievable.