Search Results for

    Show / Hide Table of Contents

    Class PropertyValidationAttribute

    Allows you to write a formula against properties that are automatically evaluated to validate changes

    Inheritance
    object
    Attribute
    ValidationAttribute
    PropertyValidationAttribute
    Inherited Members
    ValidationAttribute.FormatErrorMessage(string)
    ValidationAttribute.IsValid(object)
    ValidationAttribute.GetValidationResult(object, ValidationContext)
    ValidationAttribute.Validate(object, string)
    ValidationAttribute.Validate(object, ValidationContext)
    ValidationAttribute.ErrorMessageString
    ValidationAttribute.ErrorMessage
    ValidationAttribute.ErrorMessageResourceName
    ValidationAttribute.ErrorMessageResourceType
    Attribute.GetCustomAttributes(MemberInfo, Type)
    Attribute.GetCustomAttributes(MemberInfo, Type, bool)
    Attribute.GetCustomAttributes(MemberInfo)
    Attribute.GetCustomAttributes(MemberInfo, bool)
    Attribute.IsDefined(MemberInfo, Type)
    Attribute.IsDefined(MemberInfo, Type, bool)
    Attribute.GetCustomAttribute(MemberInfo, Type)
    Attribute.GetCustomAttribute(MemberInfo, Type, bool)
    Attribute.GetCustomAttributes(ParameterInfo)
    Attribute.GetCustomAttributes(ParameterInfo, Type)
    Attribute.GetCustomAttributes(ParameterInfo, Type, bool)
    Attribute.GetCustomAttributes(ParameterInfo, bool)
    Attribute.IsDefined(ParameterInfo, Type)
    Attribute.IsDefined(ParameterInfo, Type, bool)
    Attribute.GetCustomAttribute(ParameterInfo, Type)
    Attribute.GetCustomAttribute(ParameterInfo, Type, bool)
    Attribute.GetCustomAttributes(Module, Type)
    Attribute.GetCustomAttributes(Module)
    Attribute.GetCustomAttributes(Module, bool)
    Attribute.GetCustomAttributes(Module, Type, bool)
    Attribute.IsDefined(Module, Type)
    Attribute.IsDefined(Module, Type, bool)
    Attribute.GetCustomAttribute(Module, Type)
    Attribute.GetCustomAttribute(Module, Type, bool)
    Attribute.GetCustomAttributes(Assembly, Type)
    Attribute.GetCustomAttributes(Assembly, Type, bool)
    Attribute.GetCustomAttributes(Assembly)
    Attribute.GetCustomAttributes(Assembly, bool)
    Attribute.IsDefined(Assembly, Type)
    Attribute.IsDefined(Assembly, Type, bool)
    Attribute.GetCustomAttribute(Assembly, Type)
    Attribute.GetCustomAttribute(Assembly, Type, bool)
    Attribute.Equals(object)
    Attribute.GetHashCode()
    Attribute.Match(object)
    Attribute.IsDefaultAttribute()
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    Namespace: LemonEdge.API.Attributes.Validation
    Assembly: LemonEdge.API.dll
    Syntax
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
    public class PropertyValidationAttribute : 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

    PropertyValidationAttribute(string, string, string)

    Validates this property whenever the item is changed

    Declaration
    public PropertyValidationAttribute(string checkOnLamda, string validOnLamda, string message)
    Parameters
    Type Name Description
    string checkOnLamda

    Only runs the validOnLamda check if this statement is true, otherwise it returns valid

    string validOnLamda

    valid if this check is true, false otherwise and returns message

    string message

    Returns message if validOnLamda is false

    Properties

    RequiresValidationContext

    Declaration
    public override sealed bool RequiresValidationContext { get; }
    Property Value
    Type Description
    bool
    Overrides
    ValidationAttribute.RequiresValidationContext

    TypeId

    Have to override this if AllowMultiple is true

    Declaration
    public override object TypeId { get; }
    Property Value
    Type Description
    object
    Overrides
    Attribute.TypeId

    Methods

    IsValid(object, ValidationContext)

    Declaration
    protected override sealed ValidationResult IsValid(object value, ValidationContext validationContext)
    Parameters
    Type Name Description
    object value
    ValidationContext validationContext
    Returns
    Type Description
    ValidationResult
    Overrides
    ValidationAttribute.IsValid(object, ValidationContext)

    Extension Methods

    LinqExtensions.AsArray<T>(T)
    LinqExtensions.ToArrayOfOne<T>(T)
    LinqExtensions.ToListOfOne<T>(T)
    MiscExtensions.SetIfNotEqual<T, TP>(T, Expression<Func<T, TP>>, TP)
    WeakReferenceExtensions.WeakReference(object)
    SQLExtensions.ToSQLValue(object, bool)
    ReflectionExtensions.ClearEventInvocations(object, string)
    StringExtensions.ToCSVFormatString(object, Type)
    In this article
    Back to top © LemonEdge Technologies. All rights reserved.