ValueTagAttribute Class
Tags a value so the Meziantou.Framework.TaggedValues analyzer can report when values with different tags are mixed, for instance when an order id is compared with a project id.
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)]
public sealed class ValueTagAttribute : AttributeRemarks
On a field, a property, a parameter, or a return value ([return: ValueTag("OrderId")]), the tags describe the value. When the declared type is a collection, a Nullable<T>, a Task<TResult> or a ValueTask<TResult>, the tags describe the element or the result. Use ValueTagAttribute.Key and ValueTagAttribute.Value for dictionaries.
Several tags declare a union: the value is compatible with any value that shares at least one tag.
On the assembly, ValueTagAttribute tags a property or a field of a type you do not own, for instance [assembly: ValueTag(typeof(Process), nameof(Process.Id), "ProcessId")].
Local variables cannot have attributes. Use a comment instead: Guid /* ValueTag=OrderId */ id = ...;.
- Inheritance
AttributeValueTagAttribute
Constructors
| Name | Description |
|---|---|
| ValueTagAttribute(string[]) | Initializes a new instance of the ValueTagAttribute class. |
| ValueTagAttribute(Type, string, string[]) | Initializes a new instance of the ValueTagAttribute class that tags a member of another type. |
ValueTagAttribute overloads
ValueTagAttribute(string[])
ValueTagAttribute.csInitializes a new instance of the ValueTagAttribute class.
public ValueTagAttribute(params string[] tags)Parameters
tagsstring[]- The tags of the value. Several tags declare a union.
ValueTagAttribute(Type, string, string[])
ValueTagAttribute.csInitializes a new instance of the ValueTagAttribute class that tags a member of another type.
Properties
| Name | Description |
|---|---|
| Key | Gets or sets the tag of the keys of a dictionary. |
| MemberName | Gets the name of the tagged member, when the attribute is applied to the assembly. |
| Tags | Gets the tags of the value. |
| Type | Gets the type that declares the tagged member, when the attribute is applied to the assembly. |
| Value | Gets or sets the tag of the values of a dictionary. |