我想创建一个数据注释,我需要它作为一个枚举
类似
public enum DataUsage
{
Count,
Average,
Median,
Percentage
}
然后将它打到这样的属性上(我知道语法错误,我只是想显示用法)
[MyDataAnnotation = DataUsage.Average]
public decimal CasesPerYear
{
get;
set;
}
有人可以帮忙吗?
答案 0 :(得分:2)
这样的东西?
public enum DataUsage
{
Count,
Average,
Median,
Percentage
}
public class DataAnnotationAttribute : Attribute
{
public DataAnnotationAttribute(DataUsage usage)
{
this.Usage = usage;
}
public DataUsage Usage { get; private set; }
}
[DataAnnotation(DataUsage.Average)]
public decimal MyProperty { get; set; }