You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allows for custom validation without having to implement a validation attribute.
Constructors
public CustomAttribute(Func<object, bool> validate)
Properties
public Func<object, bool> Validator { get; } - Gets the function used to validate the value.
Methods
public override bool IsValid(object value) - Checks that the value of the data field is valid.
Examples
varvalidator=newCustomAttribute((val)=>{// Leave null and invalid type checks to other rules.if(val==null)returntrue;if(!(valisint))returntrue;varnbr=(int)val;// Super awesome validation rules here.if(nbr==123)returnfalse;returntrue;});// Prints "Is Valid: False"Console.WriteLine($"Is Valid: {validator.IsValid(123)}");