Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否可以通过属性类的';有标记吗?_C#_.net_Asp.net_Attributes - Fatal编程技术网

C# 是否可以通过属性类的';有标记吗?

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

我有一个属性来标记名为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
}

您知道,Client&Other的属性不包含DBValue值。是否有可能:如果其他开发人员没有提供DBValue,构造函数将为其分配相应的值?(对于客户端,DBValue将为0;对于其他客户端,DBValue将为2)。

否。
属性的目的是提供有关其应用到的目标的信息,没有内置功能允许属性检测其目标或与其相关的任何数据。据我所见,
DBValue
等于存储在每个枚举成员中的值,您可以轻松使用该值并从构造函数中删除
DBValue
参数。

OK。我认为这也不可能。就这样问下去,试试有没有奇迹。