CodePlexProject Hosting for Open Source Software
Is it possible to use multiple instances of the RequiredIf attribute for a property?
I am looking to do something like this:
[RequiredIf("ScheduleType", (int)Constants.PaymentSchedule.Recurring, ErrorMessage = "The {0} is required for a recurring payment.")]
[RequiredIf("ScheduleType", (int)Constants.PaymentSchedule.OnceOff, ErrorMessage = "The {0} is required for a once off payment.")]
public decimal Amount { get; set; }
I currently get this build error: "Duplicate 'RequiredIf' attribute"
Is this a .NET limitation? Are there any workarounds?
Yes, this is a .NET limitation.
The only work around is to make a new validator class and inherit from the validator that you want to duplicate.
Remember to register your the new validator. Like in the "Complex Custom Validation" section here:
This is not a .NET limitation - it depends on how you define the RequiredIfAttribute class. If you do
[AttributeUsage(AllowMultiple=true)]
public class RequiredIfAttribute : Attribute
{
// etc
}
then it will allow multiple instances of the attribute to be used - whether the library can handle there being more than one at the moment is another matter
Are you sure you want to delete this post? You will not be able to recover it later.
Are you sure you want to delete this thread? You will not be able to recover it later.