这真的令人难以置信,但真实。此代码将无法正常工作:为什么“decimal”不是有效的属性参数类型?
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field)]
public class Range : Attribute
{
public decimal Max { get; set; }
public decimal Min { get; set; }
}
public class Item
{
[Range(Min=0m,Max=1000m)] //compile error:'Min' is not a valid named attribute argument because it is not a valid attribute parameter type
public decimal Total { get; set; }
}
虽然这个工程:
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field)]
public class Range : Attribute
{
public double Max { get; set; }
public double Min { get; set; }
}
public class Item
{
[Range(Min=0d,Max=1000d)]
public decimal Total { get; set; }
}
谁能告诉我,为什么双是OK,而小数不是。
的可能重复(HTTP [使用十进制值在c#属性PARAMS?]://计算器。com/questions/507528/use-decimal-values-as-attribute-params-in-c) – nawfal 2013-06-10 22:46:30