I create the following attribute:
public class SpecificDataTypeAttribute : DataTypeAttribute
{
public SpecificDataType(DataType dataType, string field)
: base(dataType)
{
this.ErrorMessage = string.Format("{0} {1}", field, Messages.SpecificDataTypeAttribute);
}
}
And use like:
[SpecificDataType(DataType.DateTime, "Initial date")]
public DateTime? InitialDate { get; set; }
So, the message that is in Messages.SpecificDataTypeAttribute
is "is in a incorrect format."
. When i input a wrong date in InitialDate, i got the default error: "The value '12' is not valid for InitialDate."
. Why? I put the breakpoint and the code is calling the SpecificDataType ctor.