Class PropertyValidation
Allows you to write a formula against properties that are automatically evaluated to validate changes
Inheritance
System.Object
System.Attribute
System.ComponentModel.DataAnnotations.ValidationAttribute
PropertyValidation
Inherited Members
System.ComponentModel.DataAnnotations.ValidationAttribute.FormatErrorMessage(System.String)
System.ComponentModel.DataAnnotations.ValidationAttribute.GetValidationResult(System.Object, System.ComponentModel.DataAnnotations.ValidationContext)
System.ComponentModel.DataAnnotations.ValidationAttribute.IsValid(System.Object)
System.ComponentModel.DataAnnotations.ValidationAttribute.Validate(System.Object, System.ComponentModel.DataAnnotations.ValidationContext)
System.ComponentModel.DataAnnotations.ValidationAttribute.Validate(System.Object, System.String)
System.ComponentModel.DataAnnotations.ValidationAttribute.ErrorMessage
System.ComponentModel.DataAnnotations.ValidationAttribute.ErrorMessageResourceName
System.ComponentModel.DataAnnotations.ValidationAttribute.ErrorMessageResourceType
System.ComponentModel.DataAnnotations.ValidationAttribute.ErrorMessageString
System.Attribute.Equals(System.Object)
System.Attribute.GetCustomAttribute(System.Reflection.Assembly, System.Type)
System.Attribute.GetCustomAttribute(System.Reflection.Assembly, System.Type, System.Boolean)
System.Attribute.GetCustomAttribute(System.Reflection.MemberInfo, System.Type)
System.Attribute.GetCustomAttribute(System.Reflection.MemberInfo, System.Type, System.Boolean)
System.Attribute.GetCustomAttribute(System.Reflection.Module, System.Type)
System.Attribute.GetCustomAttribute(System.Reflection.Module, System.Type, System.Boolean)
System.Attribute.GetCustomAttribute(System.Reflection.ParameterInfo, System.Type)
System.Attribute.GetCustomAttribute(System.Reflection.ParameterInfo, System.Type, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.Assembly)
System.Attribute.GetCustomAttributes(System.Reflection.Assembly, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.Assembly, System.Type)
System.Attribute.GetCustomAttributes(System.Reflection.Assembly, System.Type, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo)
System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo, System.Type)
System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo, System.Type, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.Module)
System.Attribute.GetCustomAttributes(System.Reflection.Module, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.Module, System.Type)
System.Attribute.GetCustomAttributes(System.Reflection.Module, System.Type, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo)
System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo, System.Type)
System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo, System.Type, System.Boolean)
System.Attribute.GetHashCode()
System.Attribute.IsDefaultAttribute()
System.Attribute.IsDefined(System.Reflection.Assembly, System.Type)
System.Attribute.IsDefined(System.Reflection.Assembly, System.Type, System.Boolean)
System.Attribute.IsDefined(System.Reflection.MemberInfo, System.Type)
System.Attribute.IsDefined(System.Reflection.MemberInfo, System.Type, System.Boolean)
System.Attribute.IsDefined(System.Reflection.Module, System.Type)
System.Attribute.IsDefined(System.Reflection.Module, System.Type, System.Boolean)
System.Attribute.IsDefined(System.Reflection.ParameterInfo, System.Type)
System.Attribute.IsDefined(System.Reflection.ParameterInfo, System.Type, System.Boolean)
System.Attribute.Match(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: LemonEdge.API.Attributes.Validation
Assembly: API.dll
Syntax
[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
public class PropertyValidation : ValidationAttribute
Remarks
For instance you can validate properties using custom scripts like so:
public interface MyItem
{
bool ValidateX { get; set; }
[PropertyValidation(
//checkOnLamda. Only validate this property if this returns true
"MyItem." + nameof(ValidateX),
//validOnLamda. If returns false then the validation fails and the following message returns why
//This script uses LemonEdge.Core.FormulaFunctionsWithContext. So you can access the Cache, User, and Updater.
//You can also write any c# script, not just a single line formula
"var itemVaue = MyItem.AmountX; return itemValue > 100;",
//message. Reason for validation failure
"AmountX must be greater than 100 if ValidateX is true.")]
Int16 AmountX { get; set; }
}
Constructors
PropertyValidation(String, String, String)
Validates this property whenever the item is changed
Declaration
public PropertyValidation(string checkOnLamda, string validOnLamda, string message)
Parameters
Type | Name | Description |
---|---|---|
System.String | checkOnLamda | Only runs the calidOnLamda check if this statement is true, otherwise it returns valid |
System.String | validOnLamda | valid if this check is true, false otherwise and returns message |
System.String | message | Returns message if validOnLamda is false |
Properties
RequiresValidationContext
Declaration
public override sealed bool RequiresValidationContext { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
System.ComponentModel.DataAnnotations.ValidationAttribute.RequiresValidationContext
TypeId
Have to override this if AllowMultiple is true
Declaration
public override object TypeId { get; }
Property Value
Type | Description |
---|---|
System.Object |
Overrides
System.Attribute.TypeId
Methods
IsValid(Object, ValidationContext)
Declaration
protected override sealed ValidationResult IsValid(object value, ValidationContext validationContext)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | |
System.ComponentModel.DataAnnotations.ValidationContext | validationContext |
Returns
Type | Description |
---|---|
System.ComponentModel.DataAnnotations.ValidationResult |
Overrides
System.ComponentModel.DataAnnotations.ValidationAttribute.IsValid(System.Object, System.ComponentModel.DataAnnotations.ValidationContext)