So I have a simple custom validation attribute:
public class MyCustomValidator : CustomValidationAttribute
{
public bool IsLive { get; set; }
public MyCustomValidator()
{
//Service locator stuff
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
return ValidationResult.Success;
}
}
MyCustomValidor inherits the class below as all my custom validators need access to this.
public abstract class CustomValidationAttribute : ValidationAttribute
{
public Type MessageResource { get; set; }
public string MessagePrefix { get; set; }
}
Then I call this in my viewModel which looks a little like this:
public class MyViewModel
{
private static bool IsWebLive;
[MyCustomValidator(IsWebLive = IsWebLive, MessageResource = typeof(MyResourceFile), MessagePrefix = "ErrorMessage")]
public string SampleValue { get; set; }
}
Where I am passing the private IsWebLive
into the validator
I am getting an error saying an attribute argument must be a constant expression, typeof expression or array.
I know I'm probably doing this wrong. But how can I pass this bool into the Validator as I don't have access to what is setting it anywhere else in my system;
I also cannot privately set IsLive/MessageResource/MessagePrefix
in the MyCustomValidator
as my custom validator stuff is generic and MessagePrefix
and MessageResource
are accessible in all my custom validators.