Why “decimal” is not a valid attribute parameter type?

后端 未结 3 1096
名媛妹妹
名媛妹妹 2020-11-29 22:30

It is really unbelievable but real. This code will not work:

[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field)]
public class Range : Attribut         


        
3条回答
  •  遥遥无期
    2020-11-29 23:26

    The answer to this problem is to use strings, which are allowed as attributes despite not being an atomic type. Don't use doubles as rounding will make the results less accurate.

    public String MinimumValue
    {
        get
        {
            return minimumValueDecimal.ToString();
        }
    
        set
        {
            minimumValueDecimal = Decimal.Parse(value);
        }
    }
    
    private decimal minimumValueDecimal;
    

提交回复
热议问题