NArrange.VisualBasic.VBParser.ParseConditionDirective C# (CSharp) Method

ParseConditionDirective() private method

Parses a condition directive.
private ParseConditionDirective ( string line, bool &isIf ) : ConditionDirectiveElement
line string The line to process.
isIf bool Whether or not the directive is an if condition.
return NArrange.Core.CodeElements.ConditionDirectiveElement
        private ConditionDirectiveElement ParseConditionDirective(string line, out bool isIf)
        {
            int separatorIndex = line.IndexOfAny(WhiteSpaceCharacters);

            string directive = null;
            if (separatorIndex > 0)
            {
                directive = line.Substring(0, separatorIndex);
            }
            else
            {
                directive = line;
            }

            directive = VBKeyword.Normalize(directive);

            string condition = null;
            if (separatorIndex > 0)
            {
                condition = line.Substring(separatorIndex + 1).Trim();
            }

            isIf = directive == VBKeyword.If;

            switch (directive)
            {
                case VBKeyword.If:
                case VBKeyword.ElseIf:
                    if (string.IsNullOrEmpty(condition))
                    {
                        this.OnParseError("Expected a condition expression");
                    }
                    break;

                case VBKeyword.Else:
                    break;

                default:
                    this.OnParseError(
                        string.Format(
                            CultureInfo.InvariantCulture,
                            "Unhandled preprocessor directive '{0}'",
                            directive));
                    break;
            }

            ConditionDirectiveElement conditionDirective = new ConditionDirectiveElement();
            conditionDirective.ConditionExpression = condition;

            return conditionDirective;
        }