I have an attribute to mark enum fields named BusinessDescription.
public enum FailReason
{
[BusinessDescription(Description="the client cancelled the order")]
Client = 0,
[BusinessDescription(Description="vender cancelled", DBValue = 1)]
Vender = 1,
[BusinessDescription(Description="other")]
Other = 2
}
You see, the attributes of Client & Other don’t contain DBValue values. Is it possible that: if other developers didn’t give a DBValue, the constructor will assign corresponding value to it? (for Client, DBValue will be 0; for Other, DBValue will be 2).
No. The purpose of an
Attributeis to provide information about the target that it’s been applied to, there’s no built-in functionality to allow an attribute to detect its target or any data related to it. From what i seeDBValueis equal to the value stored in each of the enum’s members and you can easily use that value and remove theDBValueparameter from the constructor.