這真的令人難以置信,但真實。此代碼將無法正常工作:爲什麼「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