本文介绍了是否有可能在那里它被标记为初始化一个属性类的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须标记命名BusinessDescription枚举域的属性。

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
}

您看到,客户端和放大器的属性;其它不包含DBValue值。有没有可能是:如果其他开发商并没有给出一个DBValue,构造相应的将值分配给它? (客户端,DBValue为0;对于其他,DBValue会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).

推荐答案

没有。一个属性的目的是提供关于它已应用到目标信息,没有内置的功能,让一个属性来检测它的目标或与之相关的任何数据它。从我看到 DBValue 等于存储在每个枚举成员的值,你可以方便地使用该值并删除 DBValue 从构造函数的参数。

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.

这篇关于是否有可能在那里它被标记为初始化一个属性类的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 17:22