/// <summary> /// Creates a new ArgCantBeCombinedWith hook given an expression. This can either be an alias argument or a boolean expression of arguments (e.g. Argument1 | Argument2). Valid operators are /// and '&', or '|', and not '!'. Grouping with parentheses is also supported. Example: "(Argument1 & Argumrnt2) | Argument3". /// If the expression evaluates to true after all arguments have been populated then an UnexpectedArgumentException is thrown. /// </summary> /// <param name="expression">This can either be an alias argument or a boolean expression of arguments (e.g. Argument1 | Argument2). Valid operators are /// and '&', or '|', and not '!'. Grouping with parentheses is also supported. Example: "(Argument1 & Argumrnt2) | Argument3".</param> public ArgCantBeCombinedWith(string expression) { this.AfterPopulatePropertiesPriority = 1; try { this.Expression = BooleanExpressionParser.Parse(expression); this.ExpressionText = expression; } catch (Exception ex) { throw new InvalidArgDefinitionException("Exception parsing conditional ArgCantBeCombinedWith expression '" + expression + "' - " + ex.Message); } }
private void Evaluate(ArgHook.HookContext context, string expressionText, bool not) { try { var newExpressionText = expressionText; if (not) { newExpressionText = "!(" + expressionText + ")"; } var expression = BooleanExpressionParser.Parse(newExpressionText); var eval = expression.Evaluate(context.Definition.CreateVariableResolver()); if (not) { if (eval == true && context.CurrentArgument.RevivedValue == null) { if (TryPreventExceptionWithPrompt(context) == false) { throw new MissingArgException("The argument '" + context.CurrentArgument.DefaultAlias + "' is required if the following argument(s) are not specified: " + expressionText); } } } else { if (eval == true && context.CurrentArgument.RevivedValue == null) { if (TryPreventExceptionWithPrompt(context) == false) { throw new MissingArgException("The argument '" + context.CurrentArgument.DefaultAlias + "' is required if the following argument(s) are specified: " + expressionText); } } } } catch (MissingArgException) { throw; } catch (REPLContinueException) { throw; } catch (Exception ex) { var targetText = context.CurrentArgument.DefaultAlias + " (" + expressionText + ")"; throw new InvalidArgDefinitionException("Failed to evaluate conditional ArgRequired clause on target '" + targetText + "'" + ex.Message); } }