コード例 #1
0
        public Block BuildDocument(int indentation)
        {
            Paragraph p = new Paragraph();

            p.Inlines.Add(new Run("if")
            {
                Foreground = StyleSettings.KeyWordColor
            });
            p.Inlines.Add(" (");
            p.Inlines.AddRange(CheckExpression.BuildDocument());
            p.Inlines.Add(")");

            Section s = new Section()
            {
                Margin = new Thickness(indentation, 0, 0, 0)
            };

            s.Blocks.Add(p);
            s.Blocks.Add(IfTrueBody.BuildDocument(indentation));
            s.Blocks.Add(new Paragraph(new Run("else")
            {
                Foreground = StyleSettings.KeyWordColor
            }));
            s.Blocks.Add(IfFalseBody.BuildDocument(indentation));

            return(s);
        }
コード例 #2
0
        public void TypeCheck(ITypeEnvironment env)
        {
            if (!CheckExpression.TypeCheck(env).CompatibleWith(ExpressionType))
            {
                env.ReportError("Unable to evaluate 'if/else'. Expression must be of type bool!",
                                SourceStartPosition, SourceEndPosition);
            }

            IfTrueBody.TypeCheck(env);
            IfFalseBody.TypeCheck(env);
        }
コード例 #3
0
        public override bool Equals(object obj)
        {
            if (!(obj is IfElseStmnt))
            {
                return(false);
            }

            IfElseStmnt other = (IfElseStmnt)obj;

            return(CheckExpression.Equals(other.CheckExpression) &&
                   IfTrueBody.Equals(other.IfTrueBody) &&
                   IfFalseBody.Equals(other.IfFalseBody));
        }
コード例 #4
0
        public FrameworkElement BuildForm(IValueEnvironment vEnv, ITypeEnvironment tEnv)
        {
            ValueContainer value = CheckExpression.Evaluate(vEnv);

            FrameworkElement trueElem  = IfTrueBody.BuildForm(vEnv, tEnv);
            FrameworkElement falseElem = IfFalseBody.BuildForm(vEnv, tEnv);

            Action onValueChanged = () =>
            {
                bool boolValue = Convert.ToBoolean(value.Value);
                trueElem.Visibility  = boolValue ? Visibility.Visible : Visibility.Collapsed;
                falseElem.Visibility = !boolValue ? Visibility.Visible : Visibility.Collapsed;
            };

            value.ValueChanged += onValueChanged;
            onValueChanged();

            StackPanel sp = new StackPanel();

            sp.Children.Add(trueElem);
            sp.Children.Add(falseElem);

            return(sp);
        }
コード例 #5
0
 public override int GetHashCode()
 {
     return(CheckExpression.GetHashCode() ^ IfTrueBody.GetHashCode() ^ IfFalseBody.GetHashCode());
 }