rule-enginebusiness-rulescodeeffects

Codeeffect Rule Engine - How to define rules to check length of string


I have to define a rule like <> length is < 5 or >5 AND not equal to 'N/A'.

I am not able to get Len() function in the list of operators for the string data type.

Please suggest if any field level attributes needs to define.


Solution

  • In your source class define a method like this:

    public int Length(string str)
    {
       return string.IsNullOrEmpty(str) ? 0 : str.Length;
    }
    

    Then run your project, open the rule editor and create your rule like this:

    Check if YourString has any value and Length(YourString) is greater than [5]
    

    Details on in-rule methods can be found here