C# 是否可以通过属性类的';有标记吗?
我有一个属性来标记名为BusinessDescription的枚举字段C# 是否可以通过属性类的';有标记吗?,c#,.net,asp.net,attributes,C#,.net,Asp.net,Attributes,我有一个属性来标记名为BusinessDescription的枚举字段 public enum FailReason { [BusinessDescription(Description="the client cancelled the order")] Client = 0, [BusinessDescription(Description="vender cancelled", DBValue = 1)] Vender = 1, [BusinessDescri
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
}
您知道,Client&Other的属性不包含DBValue值。是否有可能:如果其他开发人员没有提供DBValue,构造函数将为其分配相应的值?(对于客户端,DBValue将为0;对于其他客户端,DBValue将为2)。否。
属性的目的是提供有关其应用到的目标的信息,没有内置功能允许属性检测其目标或与其相关的任何数据。据我所见,DBValue
等于存储在每个枚举成员中的值,您可以轻松使用该值并从构造函数中删除DBValue
参数。OK。我认为这也不可能。就这样问下去,试试有没有奇迹。