/// <summary>
 /// Validates that the value of the specified
 /// property does not contain any syntax errors.
 /// </summary>
 /// <param name="instance">
 /// <para>The instance to validate.</para>
 /// </param>
 /// <param name="info">
 /// <para>The property contaning the value to validate.</para>
 /// </param>
 /// <param name="errors">
 /// <para>The collection to add any errors that occur durring the validation.</para>
 /// </param>
 public override void Validate(
     object instance,
     PropertyInfo info,
     ValidationErrorCollection errors)
 {
     string expression = (string)info.GetValue(instance, null);
     if (expression != null
         && expression.Length != 0)
     {
         try
         {
             Parser parser = new Parser();
             parser.Parse(expression);
         }
         catch (SyntaxException e)
         {
             errors.Add(instance, info.Name, e.Message);
         }
     }
 }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="ExpressionTextBox"/> class.
 /// </summary>
 public ExpressionTextBox()
     : base()
 {
     parser = new Parser();
 }
Example #3
0
 private BooleanExpression Parse()
 {
     parser = new Parser();
     try
     {
         return parser.Parse(this.expressionTextBox.Text);
     }
     catch (SyntaxException ex)
     {
         MessageBox.Show(
             SR.ParseFailedMessage(ex.Message),
             SR.ParseFailedCaption,
             MessageBoxButtons.OK,
             MessageBoxIcon.Error);
         return null;
     }
 }
 private BooleanExpression GetParsedExpression(string ruleName)
 {
     AuthorizationRuleDataCollection authorizationRuleDataCollection = GetAuthorizationRules();
     AuthorizationRuleData authorizationRuleData = authorizationRuleDataCollection[ruleName];
     if (authorizationRuleData == null) return null;
     string expression = authorizationRuleData.Expression;
     Parser parser = new Parser();
     return parser.Parse(expression);
 }