views:

50

answers:

1

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).

A: 

No. The purpose of an Attribute is 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 see DBValue is equal to the value stored in each of the enum's members and you can easily use that value and remove the DBValue parameter from the constructor.

devnull
OK. I would think that it's impossible either. Just asked on SO to try if there is a miracle.
Danny Chen