GetExpressionValue() public method

Provides the value associated to this Expression
public GetExpressionValue ( DataDictionary.Interpreter.InterpretationContext context, ExplanationPart explain ) : IValue
context DataDictionary.Interpreter.InterpretationContext The context on which the value must be found
explain ExplanationPart
return IValue
        /// <summary>
        ///     Edits a value expression and provides the edited expression after user has performed his changes
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        private Expression EditExpression(Expression expression)
        {
            Expression retVal = expression;

            if (expression != null)
            {
                ModelElement.DontRaiseError(() =>
                {
                    InterpretationContext context = new InterpretationContext(Model) {UseDefaultValue = false};
                    IValue value = expression.GetExpressionValue(context, null);
                    if (value != null)
                    {
                        StructureEditor.Window window = new StructureEditor.Window();
                        window.SetModel(value);
                        window.ShowDialog();

                        string newExpression = value.ToExpressionWithDefault();
                        const bool doSemanticalAnalysis = true;
                        const bool silent = true;
                        retVal = new Parser().Expression(expression.Root, newExpression,
                            AllMatches.INSTANCE, doSemanticalAnalysis, null, silent);
                    }
                });
            }

            return retVal;
        }
Esempio n. 2
0
        /// <summary>
        ///     Provides the value of the expression provided
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="expression"></param>
        /// <param name="explain"></param>
        /// <returns></returns>
        private bool getBoolValue(ModelElement instance, Expression expression, ExplanationPart explain)
        {
            bool retVal;

            InterpretationContext context = new InterpretationContext(instance);
            BoolValue val = expression.GetExpressionValue(context, explain) as BoolValue;

            if (val != null)
            {
                retVal = val.Val;
            }
            else
            {
                throw new Exception("Cannot evaluate value of " + expression);
            }

            return retVal;
        }